Even and Odd printing using & operator and Loop - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Monday 6 November 2017

Even and Odd printing using & operator and Loop

#include <stdio.h>

int main()
{
    int x;
    for (x = 0; x <= 10; x++)
    {
        if (x & 1)
        {
            printf("%d - odd\n", x);
        }
        else
        {
            printf("%d - even\n", x);
        }
    }

    return 0;
}
OUTPUT
0 - even
1 - odd
2 - even
3 - odd
4 - even
5 - odd
6 - even
7 - odd
8 - even
9 - odd
10 - even

No comments:

Post a Comment

Post Top Ad