FIND LARGEST NUMBER USING TERNARY OPERATOR IN CPP
#include <iostream>
using namespace std;
int main()
{
int a,b,c,highest;
cout<<"enter your first numbers "<<endl;
cin>>a;
cout<<"enter your second numbers"<<endl;
cin>>b;
cout<<"enter your third numbers "<<endl;
cin>>c;
highest = (a>b&&a>c?a:b>c?b:c);
cout<<"your highest number is "<<highest<<endl;
return 0;
}
THIS IS BUT FOR FIND LARGEST NUMBER OUT OF FOUR NUMBERS
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,highest;
cout<<"enter your first numbers "<<endl;
cin>>a;
cout<<"enter your second numbers"<<endl;
cin>>b;
cout<<"enter your third numbers "<<endl;
cin>>c;
cout<<"enter your fourth numbers "<<endl;
cin>>d;
highest = (a>b && a>c && a>d ?a: b>c && b>d ?b: c>d ?c:d);
cout<<"your highest number is "<<highest<<endl;
return 0;
}
Comments
Post a Comment