programming tutorials,programming code,latest programming,programming theory
#include<stdio.h>
int main()
{
int a[10][10], n;
scanf("%d", &n); //Size of the matrix is taken from test data
//Use the printf statement as:
//printf("Sum of the diagonal elements is = %d",variable_name);
int i,j,sum1=0, sum2=0, sum=0;
for(i=0; i<n; i++)
for(j=0; j<n; j++)
scanf("%d", &a[i][j]);
}
for(i=0;i<n;i++)
sum1=sum1 + a[i][i];
sum2=sum2 + a[i][n-1-i];
sum = sum1+sum2;
printf("Sum of the diagonal elements is = %d",sum);
No comments:
Post a Comment