Home / Programs / Program to show the use of a conditional operator.
Programming Example

Program to show the use of a conditional operator.

👁 1,320 Views
💻 Practical Program
📘 Step by Step Learning
Program to show the use of a conditional operator.

Program Code

/* Program to show the use of a conditional operator.
  Author: Atnyla Developer */

#include<stdio.h>
#include<conio.h>
void main()
{
  int a, b;
	printf("enter value for a & b: ");
	scanf("%d%d",&a,&b);
	(a>b)?printf("a is greater \n"):printf("b is greater \n");
 
} 

Output

<b>Output 1 </b>
enter value for a & b: 44  65
b is greater
Press any key to continue . . .


<b>Output 2 </b>
enter value for a & b: 56  12
a is greater
Press any key to continue . . .

Explanation

Program to show the use of a conditional operator.
	(a>b)?printf("a is greater \n"):printf("b is greater \n");

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.