C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Check whether a number is Even or Odd

Introduction

  • An even number is divisible by 2 (num % 2 == 0).
  • An odd number is not divisible by 2 (num % 2 != 0).

This program takes an integer from the user and determines whether it is even or odd.

 

C Program: Check whether a number is Even or Odd

C

#include <stdio.h>

 

int main() {

    int num;

 

    // Input number from user

    printf("Enter a number: ");

    scanf("%d", &num);

 

    // Check even or odd

    if (num % 2 == 0) {

        printf("%d is Even.\n", num);

    } else {

        printf("%d is Odd.\n", num);

    }

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter a number: 12
12 is Even.

OUTPUT 2 :
Enter a number: 7
7 is Odd.

Explanation

  1. The user enters an integer.
  2. The program uses the modulus operator % to check divisibility by 2:
    • num % 2 == 0 → Even
    • Else → Odd
  3. Prints the result accordingly.