C Program to Check if a Number is Even or Odd

Subject: PPS (Programming for Problem Solving)

Contributed By: Sanjay

Created At: February 3, 2025

Question:


Write a C Program to Check if a Number is Even or Odd

Explanation Video:

Custom Image

Explanation:

 

A number is even if it is divisible by 2, i.e., num % 2 == 0.

Otherwise, it is odd.

We use an if-else condition to check this.

Source Code:
#include <stdio.h>
int main() {
    int num;
    printf("Enter a number: ");
    scanf("%d", &num);
    if (num % 2 == 0)
        printf("%d is even.\n", num);
    else
        printf("%d is odd.\n", num);
    return 0;
}
Input:
CASE-1:
Enter a number: 5
CASE-2:
Enter a number: 4
Output:
CASE-1:
5 is odd
CASE-2:
4 is Even
Share this Article & Support Us:
Status
printf('Loading...');