by Dinesh Thakur Category: C Programming (Pratical)

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



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.