-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program59.c
41 lines (41 loc) · 1.11 KB
/
Program59.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*Program to accept a two dimensional matrix and display the row sum, column sum and diagonal sum of elements.*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,a[20][20],i,j,rs=0,cs=0,ds=0;
printf("Enter the size of matrix\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("Enter the element\n");
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
ds+=a[i][j];
}
}
printf("Sum of diagonal elements: ");
printf("%d\n",ds);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
rs+=a[i][j];
printf("Row %d sum: %d\n",i+1,rs);
}
for(j=0;j<n;j++)
{
for(i=0;i<n;i++)
cs+=a[i][j];
printf("Column %d sum: %d\n",j+1,cs);
}
return 0;
}