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

5th Feb 2023, 2:27 PM
Ayush Singh
Ayush Singh - avatar
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
5th Feb 2023, 3:46 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 2
Bahha🐧 nice logic
11th Feb 2023, 8:12 PM
Ayush Singh
Ayush Singh - avatar
+ 1
Bahha🐧 Jayesh Mishra Thank you both for answering
11th Feb 2023, 8:12 PM
Ayush Singh
Ayush Singh - avatar
0
don't print inside loop first store it somewhere then print
5th Feb 2023, 3:03 PM
Jayesh Mishra
Jayesh Mishra - avatar