954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help me plss..

hi i need some help in this program.. using only 1 for loop..

#include<stdio.h>
void main()
{
int n;
clrscr();
for (n=1; n<=10; n--)
{
printf("\n %d",n);
}
getch();
}

*the output of this program is"
1
2
3
4
5
6
7
8
9
10

but i need to make it like this:
1        2
3        4
5        6
7        8
9        10
trowa0830
Newbie Poster
6 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

>void main()
Use this as a template:

#include <stdio.h>

int main ( void )
{
  /* Your code here */

  return 0;
}

>clrscr();
Unnecessary, anti-social, and you forgot to include .

>getch();
Unnecessary, non-portable (use getchar if you must), and you forgot to include .

>but i need to make it like this:
How about something like this:

for ( n = 1; n < 10; n += 2 )
  printf ( "%d\t%d\n", n, n + 1 );
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

thanks..
how about in this format i need the output to be like this

square   cube 
1        1        1 
2        4        8 
3        9        27 
4        16       64 
5        25       125


i think it needs some formula but i dont have any clues about it.. thanks in advance..

trowa0830
Newbie Poster
6 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

>i think it needs some formula
Do you even know how to find the square and cube of a number? It's pretty basic arithmetic, and you can use what you learned from my last post to do the output.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

nope i dont know how to find it using C.. can you teach me how to find square and cube in C??

trowa0830
Newbie Poster
6 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Do you know how to multiply two numbers in C? You can multiply a value with itself, and that's all you need to know to find the square and cube of a value.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

haha he really expecting us to do his work. nana ;) you can't do that here my friend. Narue has already shown in here sample code on her previous post. You wouldn't believe its just a 2 line of code.

Narue with your permission i gonna pinch your code.

for ( n = 1; n < 10; n += 2 )  
     printf ( "%d\t%d\n", n, n + 1 );


How would you calculate square n * n --- OK
How would you calculate cube n * n * n --- OK

If you expect more than that, god help you.

ssharish

ssharish2005
Posting Whiz in Training
253 posts since Dec 2006
Reputation Points: 73
Solved Threads: 20
 

ssharish thanks for this

How would you calculate square n * n --- OK
How would you calculate cube n * n * n --- OK


and thank you so much narue.. ive figured it now.. thanks thanks thanks thanks

trowa0830
Newbie Poster
6 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

Well done, you did get how to calculate square and cude. You learn new everyday!

ssharish

ssharish2005
Posting Whiz in Training
253 posts since Dec 2006
Reputation Points: 73
Solved Threads: 20
 

ohh i need help again in this program.. can you help me again??

trowa0830
Newbie Poster
6 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

oh oooooooooo, what is it now???

ssharish

ssharish2005
Posting Whiz in Training
253 posts since Dec 2006
Reputation Points: 73
Solved Threads: 20
 
int main()
{
        int i,limit;

        printf("Enter the Limit: ");
        scanf("%d", &limit);

        printf("%10s%10s%10s", "Number","Square","Cube");

        for( i = 0; i < limit; ++i ){

                printf("%10d%10d%10d\n", i, i*i, i*i*i);
        }

        return 0;
}


you can write like that if you want to be formatted for your output, you should glance C I-O chapter...

MustyCE
Newbie Poster
5 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

thanks sir.. but now i need another help i want a prgram that continuosly adds the number input then displays the sum when 0 is pressed. all i have is this old code for adding the sum.

#include<stdio.h>
#include<conio.h>
main()
{
int sum,n1,n2,n3,n4;
clrscr();
printf("Enter numbers: ");
scanf("%d%d%d%d",&n1,&n2,&n3,&n4);
sum=n1+n2+n3+n4;
while(1)
{
  scanf("%d",&n1);
  sum+=n1;
  if(n1==0) break;
}
 
printf("\n The sum is: %d", sum);
getch();
}
trowa0830
Newbie Poster
6 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 
thanks sir.. but now i need another help i want a prgram that continuosly adds the number input then displays the sum when 0 is pressed. all i have is this old code for adding the sum.

Perhaps you are beyond help. You have been shown some good professional programming practices already . None very hard to understand. But still you go and post an aberration of code, showing your level of commitment to do things right. Am I too harsh coming to that conclusion?
Why don't you go ahead and change that code and implement the suggestions given to you, and prove me wrong.

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You