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

Discussion in 'C Programming' started by Peanuts, Oct 11, 2006.

1. ### Peanuts

Joined:
Oct 11, 2006
Messages:
1
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

Peanuts, Oct 11, 2006

2. ### Firestone

Joined:
Nov 17, 2006
Messages:
2
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.

Firestone, Nov 17, 2006

Joined:
Nov 9, 2006
Messages:
4
Location:
Bangalore
Finding whether number is odd or even

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);
}

Rudresh R kaddipudi, Dec 4, 2006