Count even sum pairs possible by selecting two integers from two given ranges respectively | Function to count maximum even sum pairs in the given range ; Stores the count of even numbers between 1 to X ; Stores the count of odd numbers between 1 to X ; Stores the count of even numbers between 1 to Y ; Stores the count of odd numbers between 1 to Y ; Stores the count of pairs having even sum ; Retuens the count of pairs having even sum ; Driver Code
function cntEvenSumPairs ( X , Y ) { var cntXEvenNums = parseInt ( X / 2 ) ; var cntXOddNums = parseInt ( ( X + 1 ) / 2 ) ; var cntYEvenNums = parseInt ( Y / 2 ) ; var cntYOddNums = parseInt ( ( Y + 1 ) / 2 ) ; var cntPairs = ( cntXEvenNums * cntYEvenNums ) + ( cntXOddNums * cntYOddNums ) ; return cntPairs ; } var X = 2 ; var Y = 3 ; document . write ( cntEvenSumPairs ( X , Y ) ) ;