-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path40.c
More file actions
33 lines (26 loc) · 718 Bytes
/
40.c
File metadata and controls
33 lines (26 loc) · 718 Bytes
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
// Program to find sum of each row and column of matrix.
#include <stdio.h>
int main() {
int a[10][10], r, c, i, j, sum;
printf("Enter rows and columns: ");
scanf("%d %d", &r, &c);
printf("Enter matrix elements:\n");
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
scanf("%d", &a[i][j]);
for (i = 0; i < r; i++) {
sum = 0;
for (j = 0; j < c; j++) {
sum = sum + a[i][j];
}
printf("Sum of row %d = %d\n", i + 1, sum);
}
for (j = 0; j < c; j++) {
sum = 0;
for (i = 0; i < r; i++) {
sum = sum + a[i][j];
}
printf("Sum of column %d = %d\n", j + 1, sum);
}
return 0;
}