How to get largest of five numbers using arrays | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to get largest of five numbers using arrays

28th Dec 2018, 7:53 AM
Sada Ullah
Sada Ullah - avatar
3 Answers
+ 4
int nums[5] = {2,5,7,3,4}; int l = nums[0]; for(int x=1; x<5; x++) if(nums[x] > l) l = nums[x]; cout << l;
28th Dec 2018, 11:01 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 5
Add the language tag to your post. C++, Py, ..
28th Dec 2018, 9:14 AM
Babak
Babak - avatar
+ 1
Sort an array and then take five last (or first, depends on sorting) values.
28th Dec 2018, 9:42 AM
Michal
Michal - avatar