// Passing a matrix to a function
#include <iostream>
using namespace std;

double trace(double matrix[][3], int);

int main ()
{
  const int size = 3;
  double a[size][size];

  cout << "Enter elements of a square matrix of size "
       << size << endl;

  for (int i=0; i<size; i++)
  for (int j=0; j<size; j++)
     cin >> a[i][j];

  double tr = trace(a, size);

  cout << "the trace is " << tr << endl;

  return 0;
}

// returns the the trace of nxn matrix
double trace(double matrix[][3], int n)
{
  double t = 0.0;
  for(int i=0; i<n; i++)
       t += matrix[i][i];
  return t;
}
