WAP in C to check whether the number is even or odd using switch case

Back to Posts

WAP in C to check whether the number is even or odd using switch case

Write a program in C to check whether the entered number is even or odd using the switch case.

Also, check even-odd using the if-else and ternary operator or conditional operator.

A number is even if it is divisible by 2.

#include<stdio.h>

int main() {
  int n;
  printf("Enter any number:\n");
  scanf("%d",&n);
  switch(n%2) {
    case 0:
      printf("%d is even number",n);
      break;
    default:
        printf("%d is odd number",n);
  }
  return 0;
}

Output:

even odd output
even odd output

Share this post

Back to Posts