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

Q13. Write a C 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; //ternary 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 15.

Leave a Reply

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

%d bloggers like this: