Print all substring of a number without any conversion | Function to print the substrings of a number ; Calculate the total number of digits ; 0.5 has been added because of it will return double value like 99.556 ; Print all the numbers from starting position ; Update the no . ; Update the no . of digits ; Driver code
< ? php function printSubstrings ( $ n ) { $ s = ( int ) log10 ( $ n ) ; $ d = ( int ) ( pow ( 10 , $ s ) + 0.5 ) ; $ k = $ d ; while ( $ n ) { while ( $ d ) { echo ( int ) ( $ n / $ d ) . " STRNEWLINE " ; $ d = ( int ) ( $ d / 10 ) ; } $ n = $ n % $ k ; $ k = ( int ) ( $ k / 10 ) ; $ d = $ k ; } } $ n = 123 ; printSubstrings ( $ n ) ; ? >