10 's Complement of a decimal number | Function to find 10 's complement ; Calculating total digits in num ; restore num ; calculate 10 's complement ; Driver code
< ? php function complement ( $ num ) { $ i ; $ len = 0 ; $ comp ; $ temp = $ num ; while ( 1 ) { $ len ++ ; $ num = ( int ) ( $ num / 10 ) ; if ( abs ( $ num ) == 0 ) break ; } $ num = $ temp ; $ comp = pow ( 10 , $ len ) - $ num ; return $ comp ; } echo complement ( 25 ) . " STRNEWLINE " ; echo complement ( 456 ) ; ? >