How to find maximum value

Nov 2, 2019 at 6:42am
If a user inputs five values... How to find maximum value between those 5?

 
  cin>>a>>b>>c>>d>>e;

In this code we took 5 inputs, Now we have to find maximum value entered by user.
Nov 2, 2019 at 6:50am
largest = max( { a, b, c, d, e } );
Last edited on Nov 2, 2019 at 6:50am
Nov 2, 2019 at 6:54am
I have to do this only using loops. That's challenging...
Nov 2, 2019 at 7:00am
Well, unless you put them into an array so that your loop cycles through the index of an array, any loop method would have to pick them out of an initialiser list. Or you would have to read them one by one. Take your pick.

It's not challenging ... have a go.
Nov 2, 2019 at 7:15am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int a,b,c,d,e,max;
cin>>a;
max=a;
cin>>b;
if(b>max)
max=b;
cin>>c;
if(c>max)
max=c;
cin>>d;
if(d>max)
max=d;
cin>>e;
if(e>max)
max=e;
Last edited on Nov 2, 2019 at 7:16am
Nov 2, 2019 at 9:00am
I thought you wanted to use loops?
Topic archived. No new replies allowed.