by Dinesh Thakur

In this program user ask to define the ternary operator. User declares some required variables that contain values in it. Ternary operator denote by ?: this can be used as a shortcut for an if-else statement. Here user declare a condition to evaluate the method user ask to enter the value. b= (a>5?1:0); and display result on the screen as output.

Problem Statement:
This is C program that ask user to define the ternary operator.

  1. Declare the variables.
  2. Using method to evaluate the condition.
  3. Display result on the screen.

Here is C source code for using ternary operator. The output of this program shown below. 

#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("enter any value ");
scanf("%d",&a);
b=(a>5?1:0);
printf("%d",b);
getch();
}

Evaluation with Ternary Operation