Home / Programs / Write a program using a switch statement to check whether a number given by the user is odd or even
Programming Example

Write a program using a switch statement to check whether a number given by the user is odd or even

👁 6,445 Views
💻 Practical Program
📘 Step by Step Learning
Write a program using a switch statement to check whether a number given by the user is odd or even

Program Code

#include <stdio.h>
int main()
{
	int n;
	printf("\n Enter the number:");
	scanf("%d", &n);
	switch(n%2)
	{
		case 0: printf("\n EVEN");
				break;
		case 1: printf("\n ODD");
				break;
	}
	
	getch();
	return 0;
}

Output

<b> Output 1: </b>

 Enter the number:12

 EVEN


<b> Output 2: </b>

 Enter the number:11

 ODD

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.