**New course!**Every coder should learn

**Generative AI!**

+ 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.

8 Answers

+ 4

Sir how about c++ or java can you do it?

+ 2

https://code.sololearn.com/cgttZ2MWn8RA/?ref=app
I think this code may helpful for u

+ 2

Rankush thank you❤️

+ 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)

+ 1

Jason Panoy I can perform the algorithm there but I don't know how to take list inputs in these languages

+ 1

Namit Jain [INACTIVE] okay okay thank you for trying

+ 1

Rankush how about the algorithm returns the value 3

+ 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