WAP in C to check whether the number is even or odd using ternary operator

Back to Posts

WAP in C to check whether the number is even or odd using ternary operator

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

Also, check even-odd using the if-else and switch case.

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);
  (n%2) ? printf("%d is odd number",n) : printf("%d is even number",n);
  return 0;
}

Output:

even odd output

even odd output

Share this post

Back to Posts