Count pair of integers having even sum | Function to count even pairs ; Stores count of pairs having even sum ; Stores count of even numbers up to N ; Stores count of odd numbers up to N ; Stores count of even numbers up to M ; Stores count of odd numbers up to M ; Return the count ; Driver Code
function countEvenPairs ( N , M ) { let count = 0 ; nEven = parseInt ( Math . floor ( N / 2 ) ) ; nOdd = parseInt ( Math . ceil ( N / 2 ) ) ; mEven = parseInt ( Math . floor ( M / 2 ) ) ; mOdd = parseInt ( Math . ceil ( M / 2 ) ) ; count = nEven * mEven + nOdd * mOdd ; return count ; } let N = 4 ; let M = 6 ; document . write ( countEvenPairs ( N , M ) ) ;