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

Joined
Oct 11, 2006
Messages
1
Reaction score
0
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
 
Joined
Nov 17, 2006
Messages
2
Reaction score
0
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.
 
Joined
Nov 9, 2006
Messages
4
Reaction score
0
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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top