Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>

int main()
{
    int num;

    //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;
    }

    return 0;
}

Result:

Enter any number to check even or odd: 25

Number is odd

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C program to check vowel or consonant using ... >>
<< Write C program to create calculator using switch ...