code4sk/c/sourcecode/朱森森带领的奇妙冒险/2022-2023第二学期单开班第3次月考/求矩阵各行元素之和.cpp
2023-12-15 22:38:26 +08:00

50 lines
No EOL
829 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
7-2 求矩阵各行元素之和
分数 10
作者 C课程组
单位 浙江大学
本题要求编写程序求一个给定的m×n矩阵各行元素之和。
输入格式:
输入第一行给出两个正整数m和n1≤m,n≤6。随后m行每行给出n个整数其间
以空格分隔。
输出格式:
每行输出对应矩阵行元素之和。
输入样例:
3 2
6 3
1 -8
3 12
输出样例:
9
-7
15
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
*/
#include <stdio.h>
int main()
{
int m, n, i, j, sum = 0;
scanf("%d %d", &m, &n);
int A[100][100], B[100][100];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &A[i][j]);
sum += A[i][j];
}
printf("%d\n", sum);
sum = 0;
}
return 0;
}