+ 2

How do you find the largest and smallest numbers in a list? List(1,3,5,8)

13th Apr 2022, 7:16 PM
Sobir Mazbutov
20 Antworten
+ 7
Just a hint: Are you looking for the min imum and max imum number? PS: please add the language (R, Python...)
13th Apr 2022, 7:29 PM
StephBill
StephBill - avatar
+ 1
get the index of min and max by list.index(min) and list.index(max) store in variables Now you set at that index value by list[index]= value
13th Apr 2022, 8:13 PM
Jayakrishna 🇮🇳
+ 1
Thank you
13th Apr 2022, 9:20 PM
Sobir Mazbutov
+ 1
u are asking about min and max but end of ur message u say answer to be sort... those are different...
15th Apr 2022, 2:18 AM
Turan Ediz Saçaklı
Turan Ediz Saçaklı - avatar
+ 1
You can make a sort(have a lot of diferent ways), that check all the elements of the list e you select a temp var to get the value of the largest and another var to get the smallest
15th Apr 2022, 5:35 PM
Heber Sales
Heber Sales - avatar
13th Apr 2022, 7:42 PM
Sobir Mazbutov
0
min(list) max(list)
13th Apr 2022, 7:55 PM
Jayakrishna 🇮🇳
0
In Python, a list stands in [. ] in these brackets. That's enough for defining a list. After having found the relevant indices , it's easy 😉 see the code below as example...
13th Apr 2022, 8:40 PM
StephBill
StephBill - avatar
13th Apr 2022, 8:55 PM
StephBill
StephBill - avatar
0
Not the most elegant, but I hope it will do...
13th Apr 2022, 8:56 PM
StephBill
StephBill - avatar
0
min() function returns smallest and man() function returns largest number. But the answer you've submitted is a sorted array. so, either you can sort() function to this output or use any sorting algorithm like bubble sort, insertion sort or quick sort or merge sort etc.
15th Apr 2022, 3:00 AM
Anshul Khangar
Anshul Khangar - avatar
0
Max and min function
15th Apr 2022, 8:29 AM
Krishna Pal Sendhav
Krishna Pal Sendhav - avatar
0
I know only c++ , i could send the code for that in c++ if you want
15th Apr 2022, 9:22 AM
Jogireddy Kushwanth Reddy
0
#include<iostream> using namespace std; int main() { int arr[40]; int n,i,l,h,t; cout<<"Enter no: of terms : "; cin>>n; cout<<"Enter the terms : "; for(i=0;i<n;i++) { cin>>arr[i]; } int max=arr[0]; int min=arr[0]; for(i=0;i<n;i++) { if(max<arr[i]) { max=arr[i]; h=i; } if(min>arr[i]) { min=arr[i]; l=i; } } t=arr[l]; arr[l]=arr[h]; arr[h]=t; cout<<"After interchanging, the numbers are :"<<endl; for(i=0;i<n;i++) cout<<arr[i]<<"\t"; }
15th Apr 2022, 9:47 AM
Jogireddy Kushwanth Reddy
0
lst = [1,3,5,8] print("Largest number in list: " + max(lst)) print("Smallest number in list: " + min(lst))
15th Apr 2022, 11:26 AM
Mashaim Javaid
0
Search for min/max and also store their positions. Then you can swap them.
15th Apr 2022, 4:01 PM
Martin
0
Why do you answer their homework? They didn‘t even put in the effort of stating the question correctly
15th Apr 2022, 4:03 PM
John Doe
- 1
Can someone help me i wanna add Google user profile using Dom in JavaScript how can I add in simple html there is img attribute with function is created in JavaScript is $(".rounded-circle").attr('src', profile.getImageUrl()); how can I write it in Dom and set this attribute in Dom please help
15th Apr 2022, 7:40 AM
Dilpreet Singh
Dilpreet Singh - avatar
- 3
I don't know My question is : how do you exchange the largest and smallest number in a list? For example list(1,4,9,3) Answer:(9,4,1,3)
13th Apr 2022, 8:05 PM
Sobir Mazbutov
- 3
Can you write the full program code?
13th Apr 2022, 8:54 PM
Sobir Mazbutov