Check whether product of digits at even places is divisible by sum of digits at odd place of a number | Below function checks whether product of digits at even places is divisible by sum of digits at odd places ; if size is even ; if size is odd ; Driver code
< ? php function productSumDivisible ( $ n , $ size ) { $ sum = 0 ; $ product = 1 ; while ( $ n > 0 ) { if ( $ size % 2 == 0 ) { $ product *= $ n % 10 ; } else { $ sum += $ n % 10 ; } $ n = $ n / 10 ; $ size -- ; } if ( $ product % $ sum == 0 ) return true ; return false ; } $ n = 1234 ; $ len = 4 ; if ( productSumDivisible ( $ n , $ len ) ) echo " TRUE " ; else echo " FALSE " ; ? >