#include<stdio.h>
#include<conio.h>
int main()
{
int a[10][10],b[10][10],i,j,n1,n2,sum1=0,sum2=0;
printf("Enter the Size of first matrix\n");
scanf("%d",&n1);
printf("Enter the Size of Second matrix\n");
scanf("%d",&n2);
printf("Enter elements of the first matrix\n");
for(i=0;i<n1;i++)
{
for(j=0;j<n1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter elements of the second matrix\n");
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<n1;i++)
{
for(j=0;j<n1;j++)
{
if(j==i)
sum1=sum1+a[i][j];
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n2;j++)
{
if(j==i)
sum2=sum2+b[i][j];
}
}
printf("Sum of digonal elements in first matrix: %d\n",sum1);
printf("Sum of digonal elements in second matrix: %d\n",sum2);
printf("Sum of digonal elements in the both matrix: %d",sum1+sum2);
getch();
return 0;
}
Enter the Size of first matrix
3
Enter the Size of Second matrix
3
Enter elements of the first matrix
2
3
1
4
5
6
7
8
9
Enter elements of the second matrix
1
5
4
2
3
6
8
7
9
Sum of digonal elements in first matrix: 16
Sum of digonal elements in second matrix: 13
Sum of digonal elements in the both matrix: 29
--------------------------------
Process exited after 23.02 seconds with return value 0
Press any key to continue . . .