+ 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
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..
+ 2
Here is my code: https://code.sololearn.com/chlBclD8y7rF/?ref=app
+ 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
+ 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.