0
Frequency of an int in array
Hello! I have written a program on how to find the number that has a high frequency of appearances in an array but it doesn't work properly for every array I put. That is it gives me wrong output. If you could help me a bit with it. https://code.sololearn.com/cEfmO5KOezDl/?ref=app
14 Antworten
+ 4
https://code.sololearn.com/cHHLHuLCuguQ/?ref=app
+ 3
MargaritaK it works when you put curly braces after the if statement
+ 3
MargaritaK You're welcome. I think the main issue was that *pos wasn't initialized
+ 3
your welcome MargaritaK
+ 2
line 45 remove I and put max, that should solve it
edit: the curly brace after the if should solve it
+ 2
if(max<freq[i])
max=freq[i];
pos=&array[i];
==>
if(max<freq[i]) {
max=freq[i];
pos=&array[i];
}
+ 2
MargaritaK What is your input? If I enter something like "1 2 3 4 4 5 6 7", it says "Number is 4" 👌
+ 1
Anna thank you very very much, now I understand:)
+ 1
*AsterisK* thank you
0
Anna it doesn't give me any output :(
0
*AsterisK* it kept giving me the wrong output:(
0
Anna if I enter "6 3 8 2 6 8 10 11" I get 11 when I want to get 8 because it is the largest number from the two (6,8) that appear 2 times in the array
0
Anna I see, seems like I didn't notice it. Thank you :)