//program to find max and second max of 4 integers; #include <iostream> #include<iomanip> using namespace std; int main() { int n1,n2,n3,n4,max,max2; cout<<"enter 4 numbers "<<endl; cin>>n1>>n2>>n3>>n4; max =(n1>n2)?(n1>n3?(n1>n4?n1:n4):(n3>n4)?n3:n4):(n2>n3)?(n2>n4?n2:n4):n3; cout<<"max is: "<<max<<endl; max2=(n1>n2)?(n2>n3?(n2>n4?n2:n4):n3):(n1>n3)?(n1>n4?n1:n4):n3; cout<<"2nd max is: "<<max2<<endl; return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter