Sum of Diagonals of a Matrix is one of the operations performed on Matrices wherein the individual elements on the Diagonal of the Matrix are summed together.
Language : C
[sourcecode language='c']
#include
void main()
{
int a[3][3], b[3][3], sum,i,j;
sum=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“Enter the values for A: “);
scanf(“%d”, &a[i][j]);
}
}
printf(“\n\n Entered Matrix A\n\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(“\t %d”, a[i][j]);
}
printf(“\n”);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
sum=sum+a[i][j];
}
}
printf(“\nSum of the diagonals %d “, sum);
}
[/sourcecode]






