-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_sum_each_row.c
More file actions
30 lines (30 loc) · 877 Bytes
/
Copy patharray_sum_each_row.c
File metadata and controls
30 lines (30 loc) · 877 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
#include<stdio.h>
int main(){
int rows,column;
printf("enter num of rows of array\n");
scanf("%d",&rows);
printf("enter num of columns of array\n");
scanf("%d",&column);
int arr[rows][column];
printf("enter the elements in 2d array\n");
for (int i=0;i<rows;i++){
for (int j=0;j<column;j++){
scanf("%d",&arr[i][j]);
}
}
printf("\nthe 2d array /matrix is:\n\n");
for (int i=0;i<rows;i++){
for (int j=0;j<column;j++){
printf("%d ",arr[i][j]);
}printf("\n");
}
printf("\nSum of each row:\n");
for (int i = 0; i < rows; i++) {
int s = 0; // Reset sum for each row
for (int j = 0; j < column; j++) {
s = s + arr[i][j]; // Summing row elements
}
printf("Row %d sum: %d\n", i + 1, s);
}
return 0;
}