Count number of trailing zeros in product of array | Returns count of zeros in product of array ; count number of 2 s in each element ; count number of 5 s in each element ; return the minimum ; Driver Code
< ? php function countZeros ( $ a , $ n ) { $ count2 = 0 ; $ count5 = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { while ( $ a [ $ i ] % 2 == 0 ) { $ a [ $ i ] = $ a [ $ i ] / 2 ; $ count2 ++ ; } while ( $ a [ $ i ] % 5 == 0 ) { $ a [ $ i ] = $ a [ $ i ] / 5 ; $ count5 ++ ; } } return ( $ count2 < $ count5 ) ? $ count2 : $ count5 ; } $ a = array ( 10 , 100 , 20 , 30 , 50 , 90 , 12 , 80 ) ; $ n = sizeof ( $ a ) ; echo ( countZeros ( $ a , $ n ) ) ; ? >