/* THE DIAGONAL SUM OF A MATRIX */
#include<conio.h>
main()
{
int m,n,i,j,a[5][5],dsum=0;
clrscr();
printf("\n Enter the row and column size:");
scanf("%d%d",&m,&n);
if(m!=n)
{
printf("\n The diagonal sum of matrix is not possible");
}
else
{
printf("\n Enter the 'A' Matrix elements is:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n The diagonal sum of 'A' matrix is:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
dsum=dsum+a[i][j];
}
}
}
printf("%d",dsum);
getch();
}
No comments:
Post a Comment