Number of subarrays having even product | Function to count subarrays with even product ; Stores count of subarrays with even product ; Traverse the array ; Initialize product ; Update product of the subarray ; Print total count of subarrays ; Input ; Length of an array ; Function call to count subarrays with even product
function evenproduct ( arr , length ) { var count = 0 ; var i , j ; for ( i = 0 ; i < length + 1 ; i ++ ) { var product = 1 ; for ( j = i ; j < length + 1 ; j ++ ) { product *= arr [ j ] ; if ( product % 2 == 0 ) ++ count ; } } document . write ( count ) ; } var arr = [ 7 , 5 , 4 , 9 ] ; var length = arr . length ; evenproduct ( arr , length ) ;