+ 2

Write an algorithm that returns the index of the first occurrence of the largest element in the sequence s1,... sn. Example: If

The sequence is 6.2, 8.9, 4.2, 8.9, the algorithm returns the value 2.

6th Apr 2021, 10:13 AM
Jason Panoy
Jason Panoy - avatar
8 Respostas
+ 4
Sir how about c++ or java can you do it?
6th Apr 2021, 10:22 AM
Jason Panoy
Jason Panoy - avatar
+ 2
https://code.sololearn.com/cgttZ2MWn8RA/?ref=app I think this code may helpful for u
8th Apr 2021, 8:13 AM
born2code
born2code - avatar
+ 2
Rankush thank you❤️
11th Apr 2021, 3:19 PM
Jason Panoy
Jason Panoy - avatar
+ 1
Python: x = [float(i) for i in input().split(", ")] print(x.index(max(x))+1) Algo: x,y = [float(i) for i in input().split(", ")],1 for i in range(len(x)): if x[i] >= x[y-1]: y = i+1 print(y)
6th Apr 2021, 10:21 AM
Namit Jain
Namit Jain - avatar
+ 1
Jason Panoy I can perform the algorithm there but I don't know how to take list inputs in these languages
6th Apr 2021, 10:27 AM
Namit Jain
Namit Jain - avatar
+ 1
Namit Jain [INACTIVE] okay okay thank you for trying
6th Apr 2021, 10:30 AM
Jason Panoy
Jason Panoy - avatar
+ 1
Rankush how about the algorithm returns the value 3
10th Apr 2021, 3:38 AM
Jason Panoy
Jason Panoy - avatar
+ 1
double[ ] myNames = {6.2,8.9,4.2,8.9}; double max=myNames[0]; // let myNames[ 0 ] or 6.2 is my max value for(int i=0; i<myNames.length; i++){ // for accessing arrays value if(myNames[i]>max){ // if myNames[ i ] greater than max valueor 6.2 max=myNames[i]; // it stored array max value } } System.out.println(max); If u are again not understand.. U should learn array , loop, if statement very well, so u can solve this this program
10th Apr 2021, 6:22 AM
born2code
born2code - avatar