http://www.codeforwin.in/2016/10/c-program-to-count-frequency-of-digits-in-number.html?m=1 Study the loop and simple mathematical tricks.