The common number is = 5
The 5 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 4
The 4 repeated = 1 times
The common number is = 5
The 5 repeated = 1 times
The common number is = 5
The 5 repeated = 1 times
The common number is = 8
The 8 repeated = 1 times
The common number is = 9
The 9 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times
The common number is = 8
The 8 repeated = 1 times
So the value of freq[num] only shows 1 instead of calculating the number of repetition.
How can I fix it?
Well you only change freq[] at line 35, outside of any loops, so naturally it will only be incremented that one time. Did you mean to have it in the loop or something?
The common number is = 5
The common number is = 6
The common number is = 4
The common number is = 5
The common number is = 5
The common number is = 8
The common number is = 9
The common number is = 6
The common number is = 6
The common number is = 8
The 4 repeated = 1 times
The 5 repeated = 3 times
The 6 repeated = 3 times
The 8 repeated = 2 times
The 9 repeated = 1 times