Check if the sum of digits of a number N divides it | Function to check if sum of digits of a number divides it ; Calculate sum of all of digits of N ; Driver Code
< ? php function isSumDivides ( $ N ) { $ temp = $ N ; $ sum = 0 ; while ( $ temp ) { $ sum += $ temp % 10 ; $ temp = ( int ) $ temp / 10 ; } if ( $ N % $ sum == 0 ) return 1 ; else return 0 ; } $ N = 12 ; if ( isSumDivides ( $ N ) ) echo " YES " ; else echo " NO " ; ? >