#include <stdio.h>
#include <stdlib.h>
// 求总值和平均值
void scores()
{
// 创建二维数组
int scor[3][3] =
{
{100,100,100},
{90,80,20},
{30,10,70}
};
// 行数
int row = sizeof(scor) / sizeof(scor[0]);
// 列数
int col = sizeof(scor[0]) / sizeof(scor[0][0]);
for (int i = 0; i < row; i++)
{
// 存放总值
int sum = 0;
for (int j = 0; j < col; j++)
{
sum += scor[i][j];
}
printf("第 %d 总值是:%d\n", i+1, sum);
// 保留小数点后两位 1.0*转为小数类型
printf("第 %d 平均值是: %.2lf\n",i+1, 1.0*sum / col);
}
}
int main()
{
scores();
system("pause");
return EXIT_SUCCESS;
}
06-22
05-16
08-11
5865
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交