Write a program to print the numbers between 1 and 10, along with an indication of whether each is even or odd, like this:
1 is odd
2 is even
3 is odd
...
(Hint: use the % operator)
Hey guys tried out some c programming but can you really try out this and how wud your code look like?
Just for a different look, this would work too!
for (i = 1; i %26lt;= 10; i++)
{
printf ("%d is %s\n", i, (i % 2) ? "odd" : "even");
}
Reply:its not in c but pretty much same.
for(int x=1; x%26lt;=10; x++)
{
if(x % 2 == 0)
cout%26lt;%26lt;x%26lt;%26lt;"is even"%26lt;%26lt;endl;
else if(x % 2 == 1)
cout%26lt;%26lt;x%26lt;%26lt;"is odd"%26lt;%26lt;endl;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment