+ 1

Find the largest and smallest number in an array and swap those numbers without using functions method.

Print the array by swapping only smallest and largest element. Please help me solve this.

6th Apr 2018, 6:33 AM
Uzair Saeed
Uzair Saeed - avatar
5 Answers
+ 4
Sort the array, before swapping the first and last element.
6th Apr 2018, 6:39 AM
Fox
Fox - avatar
+ 4
This is a starting point: https://code.sololearn.com/c63K169QjJhh/?ref=app And then, I'd recommend you traversing the array with a range based reference for loop and storing references to min and max. You can then call my function with these and you're done.
6th Apr 2018, 7:30 AM
Timon Paßlick
+ 2
My suggested solution is generic so that the question of Luciano Ariel Caputi would not matter.
6th Apr 2018, 7:56 AM
Timon Paßlick
+ 2
Jay Matthews That's what I just said.
6th Apr 2018, 8:04 AM
Timon Paßlick
+ 1
How is the array? 1) 24513 => min = 1 / max = 5 2) "home" "car" "years" "yellow" "tomorrow" => min = "car" / max = "tomorrow"
6th Apr 2018, 7:50 AM
Luciano Ariel Caputi
Luciano Ariel Caputi - avatar