C++ Program to Check if Given Number is Odd or Even using Switch Case

Write C++ Program to Check if Given Number is Odd or Even using Switch Case

// CPP Program to check if given number is odd or even using switch case

#include <iostream>

using namespace std;

int main()
{
	int n;

	cout << "Enter the number :--> ";
	cin >> n;

	int x = n % 2;

	switch(x)
    {
        case 0:
            cout << "Number is Even";
            break;

        case 1:
            cout << "Number is Odd";
            break;
    }

	return 0;
}

Output:

Run 1:
Enter the number :--> 56
Number is Even

Run 2:
Enter the number :--> 57
Number is Odd

≪ Previous | Next ≫