#include<stdio.h>
main()
{
int a[50][50],m,n;
int i,j,d1=0,d2=0;
printf("Enter no. of rows and columns(order)\t");
scanf("%d%d",&m,&n);
printf("Enter the elements of matrix:\n");
if(m==n)
{
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d",&a[i][j]);
printf("matrix representation of above elemnts 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,j=n-1;i<m||j>=0;i++,j--)
{
d1=d1+a[i][i];
d2=d2+a[i][j];
}
printf("\nFirst diagonal's SUM\t%d",d1);
printf("\nSecond diagonal's SUM\t %d",d2);
}
else
printf("This program is only applicable to square matrices!!!");
}
main()
{
int a[50][50],m,n;
int i,j,d1=0,d2=0;
printf("Enter no. of rows and columns(order)\t");
scanf("%d%d",&m,&n);
printf("Enter the elements of matrix:\n");
if(m==n)
{
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%d",&a[i][j]);
printf("matrix representation of above elemnts 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,j=n-1;i<m||j>=0;i++,j--)
{
d1=d1+a[i][i];
d2=d2+a[i][j];
}
printf("\nFirst diagonal's SUM\t%d",d1);
printf("\nSecond diagonal's SUM\t %d",d2);
}
else
printf("This program is only applicable to square matrices!!!");
}
![]() |
| output |

No comments:
Post a Comment