+ 3

Output of indices of equal elements in an array

Hello! I need to write a program that will display an element with max value and its index or indices in the array. Like this: : 2 : 3 : 7 : 9 : 2 : 9 Max value: 9 [3, 5] I'm struggling with output of multiple indices and would be grateful for any solutions. Here is my attempt: https://code.sololearn.com/chlBclD8y7rF/?ref=app

19th Apr 2020, 8:13 PM
Alex P
Alex P - avatar
4 Respuestas
+ 2
In statement, printf("Maximum: %d [%d]", array[max], max); instead of max, you can write like this printf("Maximum: %d [", array[max]); for(int i=0;i<n;i++) { if(array[i]==array[max]) printf("%d ,", i) ; } printf("]); Your code has white spaces, remove all those... I think, it's better to - Instead of not continue when input double zeros, break loop else continue. Means change else to if, if to else conditions..
19th Apr 2020, 9:58 PM
Jayakrishna 🇮🇳
19th Apr 2020, 8:27 PM
Alex P
Alex P - avatar
+ 2
Bluesea, Jayakrishna thank you a lot! Now it works :) PS: yeah, I have white spaces there because I wrote it in another IDE. I'll correct them later
19th Apr 2020, 10:53 PM
Alex P
Alex P - avatar
+ 1
Sololearn is not meant as a place handing out solutions, but we can assist you with hints if you care to show your attempt.
19th Apr 2020, 8:18 PM
HonFu
HonFu - avatar