C Program to determine given number is odd or even without using IF

      This C program accomplishes the given task by evaluating the remainder of a given number when divided by 2 directly with in switch case to find odd or even.
So corresponding case gets evaluated depending on the remainder value.

C Program to find whether number is odd or even with out using if



Source Code :

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


edit-code-image

Sample Test cases :

1. Enter the number : 5
   ODD

2. Enter the number : 4
   EVEN

3. Enter the number : 345
   ODD

Explanation:

Step 1: Program reads a number from the user using scanf() function.

Step 2: The remainder of a given number when divided by 2 is used in switch case to evaluate the remainder

Step 3: If the remainder is zero then the given number is EVEN otherwise the number is ODD

More Content :Explore More