C Program to Check a Number is Odd or Even Using Conditional Operator

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
C program to check whether a number is odd or even using switch statement
C program to check odd or even numbers
C program to find maximum of two numbers using switch statement
C program to check whether a character is vowel or consonant using switch statement
C program to check whether a character is alphabet or digit
C program to check year is leap year or not
C Program to calculate factorial of a number
C program to find total, average and percentage marks of subjects
C Program to print fibonacci series
List of all C programs