# contains "stdio.h"
# Define the M 3 // matrix order
void main()
{
int a[M][M],I,j,sum = 0;
Printf ("Please enter %d*%d matrix: \n", m, m);
for(I = 0; I & ltm;; I++)// Enter the M*M matrix.
for(j = 0; j & ltm; j++)
{
scanf("%d ",& ampa[I][j]);
if(I = = j)sum+= a[I][j]; //Find the sum of the elements of the main diagonal.
}
Printf("\n matrix is: \ n ");
for(I = 0; I & ltm;; I++)// output matrix
{
for(j = 0; j & ltm; j++)
printf("%5d ",a[I][j]);
printf(" \ n "); //Output a newline character every m elements.
}
Printf ("\ nSum of main diagonals =%d\n", sum);
}