0

How can I solve this problem?

write a function with input and no output that takes an array of 5 integers and prints the possible minimum and maximum summation of 4 of its numbers

6th Sep 2018, 2:31 AM
Retag Tarek
Retag Tarek - avatar
2 odpowiedzi
+ 3
Refer this JavaScript code: var arr=[9,1,3,6,2]; var min_sum=0; var max_sum=0; for(i=0;i<4;i++) { var pos=i; for(j=i+1;j<5;j++) { if(arr[pos]>arr[j]) pos=j; } if(pos!=i) { var t=arr[i]; arr[i]=arr[pos]; arr[pos]=t; } min_sum+=arr[i]; } for(i=0;i<4;i++) { var pos=i; for(j=i+1;j<5;j++) { if(arr[pos]<arr[j]) pos=j; } if(pos!=i) { var t=arr[i]; arr[i]=arr[pos]; arr[pos]=t; } max_sum+=arr[i]; }
6th Sep 2018, 6:43 AM
Akshay Karande
+ 1
Akshay Karande thank you 🤗
6th Sep 2018, 6:03 PM
Retag Tarek
Retag Tarek - avatar