0
To find the most occurring digit
I wanted to make a code that finds the most occurring digit in the long number using a string (and loops). Also, I wanted it to get its input on the user's input. Below is the example: Input: 34214145 The output should be: 4 I attempted to code, but it's still wrong. https://code.sololearn.com/cA8a7A17a224
2 odpowiedzi
+ 3
I removed the last two closing curly braces and it showed me the output. the logic is fine so far, its correctly counting.
+ 2
Let's assume the digit 0 has the maximum frequency.
int max = 0;
Now we check whether that's actually true. Does digit 1 have a higher frequency? If yes we update the max variable.
if (frequency[1] > frequency[max])
max = 1;
Does the number 2 have even higher frequency?
if (frequency[2] > frequency[max])
max = 2;
Now of course all that's left to do is to turn this into a loop :)