The problem is finding the smallest and largest number of 10 inputs. Then swap the position of the largest and the smallest num | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The problem is finding the smallest and largest number of 10 inputs. Then swap the position of the largest and the smallest num

Do anyone know's a more efficient way of programming this? https://code.sololearn.com/crMtzxDa0jia/?ref=app

24th Oct 2022, 6:57 AM
NPCcode
NPCcode - avatar
2 Answers
+ 3
NPCcode one way is you can save the indexes also, no need for comparison again.
24th Oct 2022, 7:54 AM
Tina
Tina - avatar
+ 3
NPCcode you can perform the smallest/largest comparison during the input loop. It does not have to be in a separate loop. Use Tina 🕊🇺🇦🇮🇷's recommendation, too, so then you can remove two of the three loops. When the input loop is done, swap the values according to their indices.
24th Oct 2022, 8:24 AM
Brian
Brian - avatar