text: Construct a frequency array of digits of the values obtained from x ^ 1 , x ^ 2 , ... ... . . , x ^ n | Function that traverses digits in a number and modifies frequency count array ; Array to keep count of digits ; Traversing through x ^ 1 to x ^ n ; For power function , both its parameters are to be in double ; calling countDigits function on x ^ i ; Printing count of digits 0 - 9 ; Driver code
code: < ? php function countDigits ( $ val , & $ arr ) { while ( $ val > 0 ) { $ digit = $ val % 10 ; $ arr [ ( int ) ( $ digit ) ] += 1 ; $ val = ( int ) ( $ val / 10 ) ; } return ; } function countFrequency ( $ x , $ n ) { $ freq_count = array_fill ( 0 , 10 , 0 ) ; for ( $ i = 1 ; $ i < $ n + 1 ; $ i ++ ) { $ val = pow ( $ x , $ i ) ; countDigits ( $ val , $ freq_count ) ; } for ( $ i = 0 ; $ i < 10 ; $ i ++ ) { echo $ freq_count [ $ i ] . " " ; } } $ x = 15 ; $ n = 3 ; countFrequency ( $ x , $ n ) ? >