C Program to Check Whether a Number is Odd or Even Number using Switch Case Statement

  • Write a C program to check whether it is odd or even number using switch case statement.
  • How to check a number is odd or even in C.

Required Knowledge

Any numbers divisible by 2 are even numbers whereas numbers which are not divisible by 2 are odd numbers. Any even number can be represented in form of (2*N) whereas any odd number can be represented as (2*N + 1). Even Numbers examples: 2, 6 , 10, 12 Odd Number examples: 3, 5, 9 ,15

C program to check a number is Even of Odd using switch case statement

#include <stdio.h>
#include <conio.h>  
  
int main() {  
    int num;  
  
    /* Take a number as input from user
  using scanf function */
    printf("Enter an Integer\n");  
    scanf("%d", &num);  
  
    switch(num%2) {     
        /* Even numbers completely are divisible by 2  */  
        case 0: printf("%d is Even", num);  
                break;  
        /* Odd numbers are not divisible by 2 */  
        case 1: printf("%d is Odd", num);  
                break;  
    }  
    
    getch();
    return 0;  
}
Output
Enter an Integer
8
8 is Even
Enter an Integer
5
5 is Odd

Related Topics
C program to check whether a character is vowel or consonant using switch statement
C program to find sum of least and most significant digits of a number
C program to print name of days in week using switch statement
C program to count number of digits in an integerC program to check a number is odd or even using conditional operator
C program to check odd or even numbers
C program to print natural numbers in reverse order from N to 1
C program to find sum of prime numbers between 1 to N
C program to find twos complement of a binary number
C program to check whether a number is prime or not
List of all C programs