0

how to print maximum value of an array.

pls helppppp

25th Dec 2016, 8:31 AM
rahul negi
rahul negi - avatar
4 Antworten
+ 2
Use if statement and else if or else. If array exists, make a variable equal array at the beginning index when i = 0 the first element. then compare that with other numbers, if condition is not met For loop keeps incrementing and the first element is compared to other ones. if condition is met, first element equals the new element and again is compared to other elements , and then at the end if it is the highest you can cout it. I told u what u need to do, you need to be creative and code it.
25th Dec 2016, 8:38 AM
Kourosh Azizi
Kourosh Azizi - avatar
+ 1
note this might be easier to do with vectors.
25th Dec 2016, 9:09 AM
Kourosh Azizi
Kourosh Azizi - avatar
+ 1
Or in an array-case you might also want to try using a new variable (max) which equals the first element and then compare everything else to it and change it to whatever is bigger. This way you keep the original array as well.
25th Dec 2016, 1:56 PM
Norbivar
Norbivar - avatar
0
ok
25th Dec 2016, 9:16 AM
rahul negi
rahul negi - avatar