Write a program to check whether the given number is even or odd in C 

In this example, you will learn to check whether a number entered by the user is even or odd.


First Method Program to Check Even or Odd 

Code:

#include<stdio.h>

int main()
{
  
  int Number;
  printf("enter a number\n");
  scanf("%d",&Number);
   
   
    if(Number%2==0)
    printf("Number is even");
    else
    printf("Number is odd");
   
   
   
}

In the program, the integer entered by the user is stored in the variable number.

Then, whether number is perfectly divisible by 2 or not is checked using the modulus % operator.

If the number is perfectly divisible by 2,  expression number%2 == 0 evaluates to 1 (true). This means the number is even.

However, if the expression evaluates to 0 (false), the number is odd.


Second Method Program to Check Even or Odd 

Code:

#include<stdio.h>

int main()
{
  
  int Number;
  printf("enter a number\n");
  scanf("%d",&Number);
   
   
    if(Number%2)
    printf("Number is odd");
    else
    printf("Number is even");
   
   
   
}

In the program, the integer entered by the user is stored in the variable number.

Then, whether number is perfectly divisible by 2 or not is checked using the modulus % operator.

If the number is perfectly divisible by 2,  expression number%2  evaluates to 0 (false).


because "under if condition  is zero Condition is false. if expression is non zero condition ture".


Then control move else This means the number is even.

If the number is not perfectly divisible by 2, expression number%2  evaluates to 1 (Ture).

This means the number is odd.