Write a 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<iostream.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; //turnary operator

 

cout<<“\n The value of C is “<<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 *