Finding largest and smallest integer

looking for help on how to get a program to figure out which of 3 integers is the largest and smallest. I'm supposed to be using if statements, but got another way to work. If possible can someone tell me how to do the same function as below but with if statements? Much appreciated. And because I do not fully understand whats below if someone could explain it to me that would be very helpful. In a first year computer programming class. Just finished my 4th day so :0


#include <iostream>

int main()
{
using namespace std;
int a, b, c, d, e;
cout<< "Please enter three integers."<<endl;
cin >> a >> b >> c;

e = ((a < b) ? a : b);
cout << "the smallest of all is: " << ((e < c) ? e : c) << endl;

d = ((a > b) ? a : b);
cout << "the largest of all is: " << ((d > c) ? d : c) << endl;


return 0;
}
Last edited on
int x = (a ? b : c);
1
2
3
4
5
6
7
8
9
int x;
if(a)
{
    x = b;
}
else
{
    x = c;
}
Topic archived. No new replies allowed.