Count of pairs with sum N from first N natural numbers | C ++ program to count the number of pairs among the first N natural numbers with sum N ; Function to return the count of pairs ; If n is even ; Count of pairs ; Otherwise ; Driver Code
#include <iostream> NEW_LINE using namespace std ; int numberOfPairs ( int n ) { if ( n % 2 == 0 ) return n / 2 - 1 ; else return n / 2 ; } int main ( ) { int n = 8 ; cout << numberOfPairs ( n ) ; return 0 ; }