怎样用C语言编程计算二维数组每一行和每一列数的和? 麻烦测试好了发我哈!感激不尽!

2024-12-02 12:02:31
推荐回答(2个)
回答1:

#include
float score[5][6] = { 91, 79, 83, 92, 85, 80,
95, 72, 81, 90, 86, 82,
96, 80, 90, 92, 84, 88,
88, 80, 78, 86, 84, 80,
77, 76, 86, 88, 80, 85 };
void main(void){
float sum1[5] = {0,0,0,0,0};//行的和
float sum2[6] = { 0, 0, 0, 0, 0 ,0};//列的和
for (int i = 0; i < 5; i++){
for (int j = 0; j < 6; j++){
sum1[i]+= score[i][j];
}
printf_s("%f\n",sum1[i]);
}
printf_s("\n");
for (int i = 0; i < 6; i++){
for (int j = 0; j < 5; j++){
sum2[i] += score[j][i];
}
printf_s("%f\n", sum2[i]);
}
getchar();
}

回答2:

我觉得你回去睡觉比较现实.