Skip to main content

ProwessApps

Learn · Practice · Excel

C Program to check the given number is even or odd

C Code Example — Conditional Programs

ADVERTISEMENT

C Program to check the given number is even or odd

Objective

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

Algorithm / Approach

  1. Read an integer from the user.
  2. Use the Modulo operator (%) to divide the number by 2 and check the remainder.
  3. Condition: if(a % 2 == 0).
  4. If true (the remainder is 0), print "EVEN NUMBER".
  5. Else (the remainder is 1), print "ODD NUMBER".
main.c
#include<stdio.h>
int main( ) {
int a;
printf("Enter Values for A : ");
scanf("%d",&a);
if(a%2 == 0) {
printf("%d is EVEN NUMBER\n",a) ;
}
else {
printf("%d is ODD NUMBER\n",a);
}
return 0;
}

Expected Output

Enter Values for A : 18
18 is EVEN NUMBER

Explanation of the Program

  • This is the standard algorithm for determining even/odd parity in programming.
  • The Modulo operator (%) returns the remainder of a division operation. Since all even numbers are perfectly divisible by 2, their remainder is always 0. Odd numbers always leave a remainder of 1.

Complexity

Time Complexity O(1)
Space Complexity O(1)
ADVERTISEMENT