0

Can we find largest number from an array of integers without using if else statements?

18th Mar 2018, 3:36 PM
Jyoti
6 Réponses
+ 9
What John said. You can also just say a = [1,7,4,2,0,8,6,3,5,9] print(max(a))
18th Mar 2018, 5:18 PM
David Ashton
David Ashton - avatar
+ 5
Ternary Operator can be used too
18th Mar 2018, 5:27 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 4
I didn't use any, but there still was some buried within the library. a = [1,7,4,2,0,8,6,3,5,9] m = a[0] for i in a: m = max(i, m) print(m)
18th Mar 2018, 4:00 PM
John Wells
John Wells - avatar
+ 4
Yes, here is an example in JavaScript: https://code.sololearn.com/WKU1By30eJZF/
18th Mar 2018, 6:50 PM
Bill Zelenko
Bill Zelenko - avatar
+ 2
C#: int[] a = new int[] {0, 1, 3, 6, 12}; Console.WriteLine(a.Max());
18th Mar 2018, 6:55 PM
hinanawi
hinanawi - avatar
0
Well I know in java: int max = array.get(0); for(int i=1;i < array.length;i++){ if(array.get(i) > max) max = array.get(i); }
18th Mar 2018, 3:42 PM
Ariela
Ariela - avatar