#include<stdio.h>
main()
{
int i,j,a[10][10],sum,m,n;
printf("\nEnter the number of Rows : ");
scanf ("%d",&m);
printf("\nEnter the number of Columns : ");
scanf ("%d",&n);
for(i=0;i<m;i++ )
for(j=0;j<n;j++)
{
printf("\nEnter the Element a[%d][%d] : ", i , j);
scanf("%d",&a[i][j]);
}
sum = 0;
for(i=0;i<m;i++ )
for(j=0;j<n;j++)
{
if ( i == j )
sum = sum + a[i][j];
}
printf("\n Result after adding Diagonal Elements: %d\n",sum);
}
main()
{
int i,j,a[10][10],sum,m,n;
printf("\nEnter the number of Rows : ");
scanf ("%d",&m);
printf("\nEnter the number of Columns : ");
scanf ("%d",&n);
for(i=0;i<m;i++ )
for(j=0;j<n;j++)
{
printf("\nEnter the Element a[%d][%d] : ", i , j);
scanf("%d",&a[i][j]);
}
sum = 0;
for(i=0;i<m;i++ )
for(j=0;j<n;j++)
{
if ( i == j )
sum = sum + a[i][j];
}
printf("\n Result after adding Diagonal Elements: %d\n",sum);
}
No comments:
Post a Comment