Split N ^ 2 numbers into N groups of equal sum | C ++ implementation of the above approach ; Function to print N groups of equal sum ; No . of Groups ; n / 2 pairs ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printGroups ( int n ) { int x = 1 ; int y = n * n ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n / 2 ; j ++ ) { cout << " { ▁ " << x << " , ▁ " << y << " } ▁ " ; x ++ ; y -- ; } cout << endl ; } } int main ( ) { int n = 4 ; printGroups ( n ) ; return 0 ; }