+ 3
Help me to find largest and smallest number from array!
largest and smallest number logic
18 odpowiedzi
+ 3
The logic is simple:
We made two variables and set their values to 0(in my case to the first member of the array). Then used a for loop to loop through the array. (I commented most of this in code btw)
if there is a number greater or less than the value stored in our variables then that value is saved as the new value of the variable.
What's the other help you need?
+ 6
You might like:
https://www.sololearn.com/learn/774/?ref=app
If you just want to find lowest and highest..
let arr = [ 14, 17, 11,8, 3,2,88];
let biggest = arr[0];
let smallest = arr[0];
for(i = 0; i < arr.length ; i++){
if(arr[i] >= biggest){
biggest = arr[i];
}
if(arr[i] <= smallest){
smallest = arr[i];
}
}
+ 4
It seems you finished all the courses how could you not know this?!!!??😱
Anyway - here is the JS code
https://code.sololearn.com/W9V4a6GG74iq/?ref=app
+ 1
Think about it(second problem) yourself. Take your time.
Understand the logic first then try to code.
+ 1
ok thank you Akib Reza
+ 1
To add to Jays idea:
Check the index of the largest and smallest number and set them to NULL I guess.
I don't know of any function.
+ 1
Akib Reza do you know any function for retrieving the index of an array element?
+ 1
Akib Reza yes sir! ☺
+ 1
thank u so much Jay Matthews
+ 1
int high=0,low=arr[0];
for(int i=0;i<arr.length;i++)
{
if (arr[i]<low)
low=arr[i];
else
high=arr[i];
}
System.out.println("highest and lowest number are:"+ high +" and " + low);
0
Akib Reza thank you, but I didn't understanding anything ☺
0
😶😲...Which language do you know?
0
Akib Reza dude, I did not understand the logic
0
Akib Reza BTW, thanx I need one more Help!!!
0
i want to find second largest and second smallest number
0
Jay Matthews is there any method to remove from array?
0
😐 make one.
0
Jay Matthews I am 💔. Why python why...