Assignments » Variable, Operator and Expression » Set2 » Solution 2

Write a program which input three numbers and display the largest number using ternary operator.

#include <iostream>
using namespace std;

int main()
{
	int a,b,c,greatest;
	cout<<"Enter three numbers : ";
	cin>>a>>b>>c;
	greatest=(a>b&&a>c)?a:(b>c)?b : c;
	cout<<"Greatest number is "<<greatest;
	
	
	return 0;
}

Enter three numbers : 78 98 16
Greatest number is 98