0

how to code this..

in 200 to 1
i need to decrease by 3 and displaying odd or even numbers..

can you help me..

ty :)

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by ravenous
-1

As i understood from your question is that, you want numbers to be displayed even or oddthe number sequence will be from 200 to 1 by decreasing by 3

c=0;
for(int i=200;i>0;i=i-3)
{
    if(c)
    {
        cout<<i+" is even";
        c=1;
    }
    else
    {
        cout<<i+" is odd";
        c=0;
    }
}

Simple logic... as we know if u decrease it by 3 alternate numbers will be even, so i did like this.

You can also do by chceking if it is divisible by 2 or not..

Correct me if i am wrong.

Votes + Comments
We dont solve homework problems for others. We HELP them find their own answers
-1

Sorry small change in code...

c=0;
for(int i=200;i>0;i=i-3)
{
    if(c)
    {
        cout<<i+" is odd";
        c=0;
    }
    else
    {
        cout<<i+" is even";
        c=1;
    }
}
Votes + Comments
And again
0

You need two things to do this. Firstly, you need to make a for loop that runs over all the numbers. Secondly, you need to use the % operator on each. % gives you the "remainder" of an integer division. If you divide an integer by 2 and look at the remainder, it will be 0 for even numbers and 1 for odd numbers:

x % 2 == 0;   // if x is even
y % 2 == 1;   // if y is odd

Have a play with those ideas and see how you get on. Post your code if you have any further problems

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.