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

55 lines
No EOL
1.1 KiB
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-4 矩阵运算
分数 10
作者 C课程组
单位 浙江大学
给定一个n×n的方阵本题要求计算该矩阵除副对角线、最后一列和最后一行以外的所有元素之和。副对角线为从矩阵的右上角至左下角的连线。
输入格式:
输入第一行给出正整数n1<n≤10随后n行每行给出n个整数其间以空格分隔。
输出格式:
在一行中给出该矩阵除副对角线、最后一列和最后一行以外的所有元素之和。
输入样例:
4
2 3 4 1
5 6 1 1
7 1 8 1
1 1 1 1
输出样例:
35
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
*/
#include <stdio.h>
int main()
{
int n, i, j, sum = 0;
scanf("%d", &n);
int A[100][100];
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &A[i][j]);
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (!((i == i & j == n - i - 1) || i == n - 1 || j == n - 1))
{
sum += A[i][j];
}
}
}
printf("%d", sum);
return 0;
}