/*G M SHAHEEN SHAH SHIMON
Matric No:A20EC0266
Lab:3  Question:1
section:06*/

#include<iostream>
#include<cmath>
using namespace std;
//global constant 
const int r=3;
const int c=3;

int square_diagonal(int A[r][c]) //function header
{
	int sum =0;
	int result;
	for(int i=0;i<r;i++)
	{
		for(int x=0;x<c;x++)
		{
			if (i==x)
			{
				sum+=A[i][x];
			}
		}
	}
	result=sum*sum;
	return result;	
}

int main()
{
	int result;
	int A[r][c]; //using 2D array
	
	//taking input of 2d array from user
	cout<<"Enter the number of 2D array"<<endl;
	for(int i=0;i<r;i++)
	{
		for(int x=0;x<c;x++)
		{
			cout<<"A["<<i<<"]["<<x<<"] = ";
			cin>>A[i][x];
		}
	}
	cout<<endl;
	
	//printing the elements 
	cout<<"All elements are"<<endl;
	for(int i=0;i<r;i++)
	{
		for(int x=0;x<c;x++)
		{
			cout<<A[i][x]<<" ";
		}
		cout<<endl;
	}
	result =square_diagonal(A); //function call
	cout<<"The square of sum of all major diagonal elements is : "<<result;
	
	return 0;
}


