Home C# Check a number for Odd or Even in C

Check a number for Odd or Even in C

In this example we will check if a number is odd or even

Example

We take a number from a user and store it in a variable called number

#include<stdio.h>

int main()
{
    int number;
    printf("Enter a number:  ");
    scanf("%d",&number);

    if((number/2)*2 == number)
        printf("\n %d is Even\n", number);
    else
        printf("\n %d is Odd\n", number);

    return 0;
}

 

When you run this you will see something like this

Enter a number:  7

 7 is Odd

Enter a number:  8

 8 is Even

You may also like