#include <stdio.h>
int main(){
int n=0;
scanf("%d",&n);
while(n!=0){
int a[100][100]={0};
int x=0,y=0;
scanf("%d %d",&x,&y);
for (int i = 0; i < x;i++) {
for (int j = 0; j < y;j++) {
scanf("%d",&a[i][j]);
}
}
int sum=0;
if(x>1){
for (int i = 0; i < y; i++) {
sum=sum+a[0][i];
sum=sum+a[x-1][i];
}
} else{
for (int i = 0; i < y;i++) {
sum=sum+a[0][i];
}
}
if(x>2){
for (int i = 1; i < x-1;i++) {
sum=sum+a[i][0];
sum=sum+a[i][y-1];
}
}
printf("%d\n",sum);
n--;
}
return 0;
}
计算矩阵边缘元素之和C语言
最新推荐文章于 2024-03-30 14:19:28 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)