C Program To Make Use Of Ternary Operator/Conditional Operator.

Q14. Write a program to make use of ternary operator/conditional operator.

Solution:

#include<stdio.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a,b,c;

 

clrscr(); //for clearing the screen

 

a=10;

b=15;

 

c=a>b?a:b>a?a:b; //turnary operator

 

printf(“\n The value of C is %d.”,c);

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

The value of C is 10.

Leave a Reply

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

%d bloggers like this: