#include <iostream>
#include <cmath>
const int rows = 3; // rows is the number of rows of 2D array
const int cols = 3; // cols is the number of columns of 2D array
using namespace std;
int sum2(int [][cols], int); // sum2 is the function of calculating square of sum of the main diagonal of the 2D array

int main()
{
	int elements[rows][cols]; // elements is the 2D array
	int sum = 0; // sum is used to hold the result of square of sum of the main diagonal of the 2D array
	
	cout << "Please enter the elements of 2D array with size 3x3: ";
	
	for (int x = 0; x < rows; x++)
	{
		for (int y = 0; y < cols; y++)
		{
			cin >> elements[x][y];
		}
	}
	
	cout << "all elements are";
	
	for (int i = 0; i < rows; i++)
	{
		cout << endl;
		
		for (int j = 0; j < cols; j++)
		{
			cout << elements[i][j] << " " ;
		}
	} 
	
	cout << endl;
	
	sum = sum2(elements, rows);
	
	cout << "square of sum of all major diagonal elements is " << sum;
	
	return 0;
} 

int sum2(int elements[][cols], int rows)
{
	int sum = 0; // To hold the sum of the main diagonal of the 2D array
	
	for (int a = 0; a < rows; a++)
	{
		for (int b = 0; b < cols; b++)
		{
			if (a == b)
			{
				sum += elements[a][b]; 
			}
		}
	}
	
	return pow(sum, 2); // Return square of sum
}
