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

  • Write a C program to check whether a number is odd or even using conditional operator.
  • Wap in C to check whether a number is odd or even using ternary operator

Required Knowledge

In this program, we will use conditional operator to check a number is odd or even.

C program to check whether a number is odd or even using conditional operator

#include <stdio.h>  
  
int main() {  
    int num, isEven;  
  
    /* Take a number as input from user
  using scanf function */
    printf("Enter an Integer\n");  
    scanf("%d", &num); 
    
    /* Finds input number is Odd or Even 
 using Ternary Operator */  
    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