Velocity Reviews > Using C, Looping using IF to prints numbers 1-10 to say whether odd or even

# Using C, Looping using IF to prints numbers 1-10 to say whether odd or even

Peanuts
Junior Member
Join Date: Oct 2006
Posts: 1

 10-11-2006
Can you help me construct a programme using C.

Using looping methods and the IF constrcut to print the numbers between 1 and 10 along with an idications of whether each is even or odd. Like this

1 is odd
2 is even
3 is odd

Many Thanks

Peanuts

Firestone
Junior Member
Join Date: Nov 2006
Posts: 2

 11-17-2006
I dont know about the computer actually figuring it out, but you can just make it every other like:

#include <stdio.h>
int main(void)
{
int a;
a=1;
while (a<=10)
{
printf("\n%d is odd",a);
a=a+1;
printf("\n%d is even",a);
a=a+1;
}

printf("\n\n");
return 0;
}
Should do it.

Junior Member
Join Date: Nov 2006
Location: Bangalore
Posts: 4

 12-04-2006
Logic: Odd numbers yields 1 as remainder when it is divided by 2;

int a=0;
while(a<=10)
{
if(a++%2>0)
printf("%d is Odd",a);
else
printf("%d is Even",a);
}