Count of pairs with sum N from first N natural numbers | Function to return the count of pairs ; If n is even ; Count of pairs ; Otherwise ; Driver code
function numberOfPairs ( n ) { if ( n % 2 == 0 ) return ( n / 2 - 1 ) ; else return ( n / 2 ) ; } let n = 8 ; document . write ( numberOfPairs ( n ) ) ;