Count number of ordered pairs with Even and Odd Sums | function to count odd sum pair ; if number is even ; if number is odd ; count of ordered pairs ; function to count even sum pair ; Driver code
function count_odd_pair ( n , a ) { var odd = 0 , even = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } var ans = odd * even * 2 ; return ans ; } function count_even_pair ( odd_sum_pairs , n ) { var total_pairs = ( n * ( n - 1 ) ) ; var ans = total_pairs - odd_sum_pairs ; return ans ; } var n = 6 ; var a = [ 2 , 4 , 5 , 9 , 1 , 8 ] ; var odd_sum_pairs = count_odd_pair ( n , a ) ; var even_sum_pairs = count_even_pair ( odd_sum_pairs , n ) ; document . write ( " " + even_sum_pairs + " " ) ; document . write ( " " + odd_sum_pairs + " " ) ;