Skip to content
Home » program to find whether the number is odd or even using the conditional operator in C.

program to find whether the number is odd or even using the conditional operator in C.

Learn about program to find whether the given number is odd or even using the conditional operator in C. in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

program to find whether the given number is odd or even using the conditional operator in C.

Program:

#include<stdio.h>
int main()
{
  int num;
  printf("Enter a number: ");
  scanf("%d", &num);
  (num%2==0)? printf("Even"): printf("Odd");
  return 0;
}

Output:

Enter a number: 2
Even

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

Similar Codes :
C program to find whether the number is positive or negative using the conditional operator.
C program to find the maximum in the given two numbers using the conditional operator