/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
int main()
{
int i,j,m,n,sum1=0,sum2=0;
printf("enter the rows and columns");
scanf("%d%d",&m,&n);
int a[m][n];
printf("enter the elements in the matrix");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
sum1=sum1+a[i][j];
}
}
printf("sum of first diagonal is %d",sum1);
for(i=0,j=(n-1);i<m,j>=0;i++,j--)
{
sum2=sum2+a[i][j];
}
printf("\nsum of second diagonal is %d",sum2);
printf("\nsum of the two diagonals is %d.",sum1+sum2);
return 0;
}