C Program to Check Whether a Number is Even or Odd

Number is Even or Odd

We can determine whether a number is even or odd. This can be tested using different methods. The test can be done using simple methods such as testing the number’s divisibility by 2. If the remainder is zero, the number is even. If the remainder is not zero, the number is odd. The following algorithm describes how a C program can test if a number is even or odd.

Ex. number is 24

it is an even number because it is exactly divisible by 2 

number is 15

it is odd number  because it is not divisible by 2

C program to check A number is even or odd (1)

Working:-

Step 1. Start

Step 2. Enter a number.

Step 3. If the number is divisible by 2, it is even.

Step 4. If the number is not divisible by 2, it is odd.

Step 5. Stop

C Program to test if a number is Even or Odd    

#include<stdio.h> 
int main()
{
     int number; 
     printf("Insert a number \n");
     scanf("%d",&number);
   
  //Checking if the number is divisible by 2 
    if (number%2 == 0)
      printf("The number is even\n");
   
    else      
      printf("The number is odd\n");
   return 0;
}

Output

Insert a number: 3
The number is odd

Insert a number: 2
The number is even

Please Login/Signup to comment