ternary operator program in c
C programming Tutorials

Even Odd Program Using Ternary Operator

Even Odd Program Using Ternary Operator

In C Programming ternary operator or conditional operator is an alternative of if else statement in c programming.

syntax of ternary operator is given as

( condition ) ? expression 1 : expression 2

if the mentioned condition is true then expression 1 will be execute otherwise expression 2 will be execute.

Example – Program to check that given number is even or odd using ternary operator is given here –

#include <stdio.h>

#include<conio.h>
void main( )
{
int num;
scanf(“%d”, &num);
(num % 2 == 0)? printf(“The given number is even”) : printf(“The given number is odd”);
getch();
}

Output

ternary operator program in c

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *