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 ; Driver Code ; Input ; Length of an array ; Function call to count subarrays with even product
def evenproduct ( arr , length ) : NEW_LINE INDENT count = 0 ; NEW_LINE for i in range ( length + 1 ) : NEW_LINE INDENT product = 1 ; NEW_LINE for j in range ( i , length + 1 ) : NEW_LINE product *= arr [ j ] ; NEW_LINE if ( product % 2 == 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT print ( count ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 7 , 5 , 4 , 9 ] ; NEW_LINE length = len ( arr ) - 1 ; NEW_LINE evenproduct ( arr , length ) ; NEW_LINE DEDENT