// Program by Akash Tripathi (@proakash256)
#include <stdio.h>
int main()
{
int r , s = 0 , a = 0;
printf("Enter the number of Rows and Columns: ");
scanf("%d" , &r);
int ar[r][r];
printf("\nEnter the elements (row wise):\n");
for(int i = 0; i < r; i = i + 1)
{
for(int j = 0; j < r; j = j + 1)
{
scanf("%d" , &ar[i][j]);
if(i == j)
s = s + ar[i][j];
if(j == (r - 1 - i))
a = a + ar[i][j];
}
}
printf("\nThe given matrix is :\n\n");
for(int i = 0; i < r; i = i + 1)
{
for(int j = 0; j < r; j = j + 1)
printf("%d\t" , ar[i][j]);
printf("\n");
}
printf("\nThe Sum of the Right Diagonal elements
of the given Matrix is %d\n\n" , s);
printf("\nThe Sum of the Left Diagonal elements
of the given Matrix is %d\n\n" , a);
return 0;
}
Comments
Post a Comment