To check even or odd number

Write program to check even or odd number using switch case.


Source Code:

#include <stdio.h>
#include <conio.h>
void main()
{
    int num;
    clrscr();
    //Reading a number from user
    printf("Enter any number to check even or odd: ");
    scanf("%d", &num);

    switch(num % 2)
    {
        //If n%2 == 0
        case 0: printf("Number is even");
                break;

        //Else if n%2 == 1
        case 1: printf("Number is odd");
                break;
    }

    getch();
}

Output:

Enter any number to check even or odd: 5
Number id Odd

Leave a Reply

Your email address will not be published. Required fields are marked *