Narcissistic number | Function to count digits ; Returns true if n is Narcissistic number ; count the number of digits ; calculates the sum of digits raised to power ; Driver Code
< ? php function countDigit ( $ n ) { if ( $ n == 0 ) return 0 ; return ( 1 + countDigit ( $ n / 10 ) ) ; } function check ( $ n ) { $ l = countDigit ( $ n ) ; $ dup = $ n ; $ sum = 0 ; while ( $ dup ) { $ sum += pow ( $ dup % 10 , $ l ) ; $ dup = ( int ) $ dup / 10 ; } return ( $ n == $ sum ) ; } $ n = 1634 ; if ( check ( ! $ n ) ) echo " yes " ; else echo " no " ; ? >