Input a 4*3 table, calculate the sum of each row. Inut: 12 integers in 4*3 tabel Output: 4 integers with each one in single line(c语言)
时间: 2024-03-09 16:45:24 浏览: 101
Alright, here's the code in C language to calculate the sum of each row in a 4x3 table:
```c
#include <stdio.h>
int main() {
int table[4][3];
int row_sum[4] = {0};
// input values for the table
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
scanf("%d", &table[i][j]);
}
}
// calculate sum of each row
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
row_sum[i] += table[i][j];
}
}
// output sum of each row
for (int i = 0; i < 4; i++) {
printf("%d\n", row_sum[i]);
}
return 0;
}
```
You can input the 12 integers in the 4x3 table and the program will output the sum of each row in separate lines.
阅读全文