Tuesday, July 28, 2009

C programming help...?

I am a beginner level programmer in C. Can someone please help me by telling me if the following program will give the desired ouput of generating 'n' number of even nos...





#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;


void main ();


{


int i,n;


clrscr ();


printf (“\n Enter the number of even nos you want to print: ”);


scanf (“%d”,n);


i=0;


while (i%26lt;=2n)


{


printf (“%d”,i);


i=i+2;


}


getch ();


}

C programming help...?
Here's the correct program:





#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;


void main()


{


int i,n;


clrscr();


printf("\nEnter the number of even nos you want to print: ");


scanf("%d",n);


i = 0;


while(i%26lt;=2*n)


{


printf("%d",i);


i=i+2


}


getch();


}





Compare this one with the one you wrote and find out the errors.


This program will start an infinite loop and you will have to press Ctrl + C to exit.
Reply:You cannt use 2n, you need 2 * n Report It

Reply:compile!
Reply:I don't think so.
Reply:while(i%26lt;2*n) is correct


No comments:

Post a Comment