text: Probability of rain on N + 1 th day | Function to find the probability ; count 1 ; find probability ; Driver Code
code: < ? php function rainDayProbability ( $ a , $ n ) { $ count = 0 ; $ m ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ a [ $ i ] == 1 ) $ count ++ ; } $ m = $ count / $ n ; return $ m ; } $ a = array ( 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 ) ; $ n = count ( $ a ) ; echo rainDayProbability ( $ a , $ n ) ; ? >