find max and second max of 4 input integers

PHOTO EMBED

Thu Oct 05 2023 16:07:48 GMT+0000 (Coordinated Universal Time)

Saved by @yolobotoffender

// Online C++ compiler to run C++ program online
#include <iostream>
#include<iomanip>
using namespace std;
int main() {                //Write a C++ program that takes three numbers as input and uses the ternary operator to find and print the maximum of the three numbers.

int n1,n2,n3,n4,max,max2,d;
char invalid;
cout<<"enter four numbers"<<endl;
cin>>n1>>n2>>n3>>n4;
max = (n1>n2)?(n1>n3)?(n1>n4)?n1:n2:((n3>n2)?n3:n2):(n4>n3)?n4:n3;
cout<<"max value is "<<max<<endl;
max2 = (max>n1)?n1:(max>n2)?n2:(max>n3)?n3:(max>n4)?n4:invalid;
cout<<"2nd max value is "<<max2<<endl;
content_copyCOPY