0
Frequency counting program
I am working on a program that counts the frequency of digits in a number. I have completed the program but facing a problem that my program counts the same digit as many times as it appears but it is required to count the digits only one time. Frequency: the no. of appearance of digits. For example: in 6665 the frequency of 5 is one and frequency of 6 is three. https://code.sololearn.com/cuxSxHS6jQI4/?ref=app
4 Respostas
0
https://code.sololearn.com/c7FiXVG11SIo/?ref=app
here is an approach .
create an array with 10 elements because in base 10 we have ten digits from 0 to 9.
use digits as array index to increment their occurrences.
for example if b = 5 . then counter[5] += 1 ; will increment occurrence of 5.
then loop through the array and print only elements that are not 0.
I didn't change your code logic. I only added an array and incremented its elements then print them.
things I added are commented
+ 2
Bahha🐧 nice logic
+ 1
Bahha🐧
Jayesh Mishra
Thank you both for answering
0
don't print inside loop first store it somewhere then print