#include<stdio.h>

main()

{

int a[10][10],s,i,j,r,c;

printf("Enter the order of the matrix\n");

scanf("%d%d",&r,&c);

printf("Enter the values\n");

for(i=0;i<r;i++)

{

for(j=0;j<c;j++)

{

scanf("%d",&a[i][j]);

}

}

printf("\nThe matrix is\n");

for(i=0;i<r;i++)

{

for(j=0;j<c;j++)

{

printf("%d\t",a[i][j]);

}

printf("\n");

}

s=0;

if(r==c)

{

for(i=0;i<r;i++)

{

for(j=0;j<c;j++)

{

if(i==j)

s=s+a[i][j];

}

}

printf("\nSum of diagonal elements = %d",s);

}

else

printf("\nNo diagonal elements");

printf("\n");

}

**You Like It!? Then kindly share with your Friends.**