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

23rd May 2019, 8:27 PM
MargaritaK
14 Antworten
+ 4
https://code.sololearn.com/cHHLHuLCuguQ/?ref=app
23rd May 2019, 9:26 PM
Anna
Anna - avatar
+ 3
MargaritaK it works when you put curly braces after the if statement
23rd May 2019, 9:10 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 3
MargaritaK You're welcome. I think the main issue was that *pos wasn't initialized
23rd May 2019, 9:29 PM
Anna
Anna - avatar
+ 3
your welcome MargaritaK
23rd May 2019, 9:53 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
line 45 remove I and put max, that should solve it edit: the curly brace after the if should solve it
23rd May 2019, 9:01 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
if(max<freq[i]) max=freq[i]; pos=&array[i]; ==> if(max<freq[i]) { max=freq[i]; pos=&array[i]; }
23rd May 2019, 9:02 PM
Anna
Anna - avatar
+ 2
MargaritaK What is your input? If I enter something like "1 2 3 4 4 5 6 7", it says "Number is 4" 👌
23rd May 2019, 9:11 PM
Anna
Anna - avatar
23rd May 2019, 9:43 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 1
Anna thank you very very much, now I understand:)
23rd May 2019, 9:28 PM
MargaritaK
+ 1
*AsterisK* thank you
23rd May 2019, 9:49 PM
MargaritaK
0
Anna it doesn't give me any output :(
23rd May 2019, 9:09 PM
MargaritaK
0
*AsterisK* it kept giving me the wrong output:(
23rd May 2019, 9:09 PM
MargaritaK
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
23rd May 2019, 9:14 PM
MargaritaK
0
Anna I see, seems like I didn't notice it. Thank you :)
23rd May 2019, 9:30 PM
MargaritaK