[RESOLVED] Display the Even numbe
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
for (i=1;i<=10;i++)
{
if (i%2==0)
printf("\n%d",i "is even number");
}
getch();
}
I want to print all the Even numbers lying between 1 to 10. My program does that.
But I want to display in the format:-
2 is even number
4 is even number
and so on......
Below LINE Do not Display the correct output:-
Code:
printf("\n%d",i "is even number");
Please help me!!!!!
Re: Display the Even numbe
Shouldn't that be:
Code:
printf("\n%d is even number", i);
http://www.cplusplus.com/reference/cstdio/printf/
Re: Display the Even numbe
Yes. the printf in the first post is incorrect... Arnoutdv's code is correct.
-tg
Re: Display the Even numbe
Just for information,
if ( (i&1) == 0) // i Anded with 1
should be a much faster operation than using the Mod % operator, which requires an integer divide in most processors that I know of.