Check whether product of digits at even places of a number is divisible by K | Below function checks whether product of digits at even places is divisible by K ; if position is even ; Driver code
< ? php function productDivisible ( $ n , $ k ) { $ product = 1 ; $ position = 1 ; while ( $ n > 0 ) { if ( $ position % 2 == 0 ) $ product *= $ n % 10 ; $ n = ( int ) ( $ n / 10 ) ; $ position ++ ; } if ( $ product % $ k == 0 ) return true ; return false ; } $ n = 321922 ; $ k = 3 ; if ( productDivisible ( $ n , $ k ) ) echo " YES " ; else echo " NO " ; ? >