+ 2
How do you find the largest and smallest numbers in a list? List(1,3,5,8)
20 ответов
+ 7
Just a hint: Are you looking for the min imum and max imum number?
PS: please add the language (R, Python...)
+ 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
+ 1
Thank you
+ 1
u are asking about min and max but end of ur message u say answer to be sort... those are different...
+ 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
0
min(list)
max(list)
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...
0
Not the most elegant, but I hope it will do...
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.
0
Max and min function
0
I know only c++ , i could send the code for that in c++ if you want
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";
}
0
lst = [1,3,5,8]
print("Largest number in list: " + max(lst))
print("Smallest number in list: " + min(lst))
0
Search for min/max and also store their positions. Then you can swap them.
0
Why do you answer their homework? They didn‘t even put in the effort of stating the question correctly
- 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
- 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)
- 3
Can you write the full program code?