#include<stdio.h>
main()
{
int a[20][20],n,i,j,diagonal,rowsum,colsum,m;
clrscr();
printf("\nEnter the Dimensions of the Matrix (M*N)\n");
scanf("%d%d",&m,&n);
if(m==n)
{
printf("\nEnter the matrix elements:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nThe Given MAtrix is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
a[i][n]=0;
for(j=0;j<n;j++)
{
a[i][n]=a[i][n]+a[i][j];
}
printf("\nRow sum=%d",a[i][n]);
}
printf("\n");
for(i=0;i<n;i++)
{
a[n][i]=0;
for(j=0;j<n;j++)
{
a[n][i]=a[n][i]+a[j][i];
}
printf("\nColumn Sum= %d",a[n][i]);
}
printf("\n");
a[n][n]=0;
for(i=0;i<n;i++)
{
a[n][n]=a[n][n]+a[i][i];
printf("\nSum of principle diagonal is: %d",a[n][n]);
}
printf("\nElements of given matrix along with row, column and principle
diagonal sum:\n");
for(i=0;i<=n;i++)
{
for(j=0;j<=m;j++)
{
printf("%5d",a[i][j]);
}
printf("\n");
}
}
getch();
}
Comments
Post a Comment