Skip to content
Home » C program using a switch case to check whether the number entered by the user is odd or even

C program using a switch case to check whether the number entered by the user is odd or even

Learn about C program using a switch case to check whether the number entered by the user is odd or even in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C program using a switch case to check whether the number entered by the user is odd or even

Program:

#include<stdio.h>
int main()
{
  int number;

  printf("Enter a number: ");
  scanf("%d",&number);

  switch( number%2 )
  {
    case 0:
      printf("%d is even.", number);
      break;
    case 1:
      printf("%d is odd.", number);
  }

  return 0;
}

Output:

Enter a number: 7
7 is odd.

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Check Character is a lower, upper, digit or special character in C
Check Eligibility for Marriage in C