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
Input sample:
12 4 6
8 23 3
15 7 9
2 5 17
output sample:
22
34
31
24
参考GPT和自己的思路:
好的,针对这个问题,你可以使用以下的 Python 代码实现计算每一行的和:
table = []
for i in range(4):
row = input().split() # 读取输入的一行,以空格分隔的整数字符串
row = [int(x) for x in row] # 把字符串列表转换成整数列表
table.append(row) # 把该行添加到表格中
row_sums = []
for row in table:
row_sum = sum(row) # 计算该行的和
row_sums.append(row_sum) # 添加该行的和到列表中
for sum in row_sums:
print(sum) # 输出每一行的和
你可以把这段代码复制到 Python 环境中运行,然后输入示例中给定的数值,即可得到该表格每一行的和。希望我的回答能够帮到你!
#include <stdio.h>
#include "math.h"
int main(){
int a[4][3]={0};
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
scanf("%d",&a[i][j]);
}
}
int x,b,c,d;
x = a[0][0]+a[0][1]+a[0][2];
b = a[1][0]+a[1][1]+a[1][2];
c = a[2][0]+a[2][1]+a[2][2];
d = a[3][0]+a[3][1]+a[3][2];
printf("%d\n%d\n%d\n%d\n",x,b,c,d);
}