In this C program, we will use check whether a number is odd or even using conditional operator.
Required Knowledge
C program to check whether a number is odd or even using conditional operator
#include <stdio.h> int main() { int num, isEven; printf("Enter an Integer\n"); scanf("%d", &num); isEven = (num%2 == 1) ? 0 : 1; if(isEven == 1) printf("%d is Even\n", num); else printf("%d is Odd\n", num); return 0; }Output
Enter an Integer 3 3 is Odd
Enter an Integer 4 4 is Even
Related Topics