使用C编写程序,实现输入30个学生6门课的成绩,并输出每个学生的总成绩和平均成赚。
时间: 2024-02-11 09:09:39 浏览: 32
好的,以下是C语言代码实现:
```c
#include <stdio.h>
int main() {
float scores[30][6]; // 存储学生成绩的二维数组
float total_score, avg_score; // 总成绩和平均成绩
// 输入30个学生的6门课成绩
for (int i = 0; i < 30; i++) {
printf("请输入第%d个学生的6门课成绩:\n", i+1);
for (int j = 0; j < 6; j++) {
scanf("%f", &scores[i][j]);
}
}
// 计算每个学生的总成绩和平均成绩,并输出结果
for (int i = 0; i < 30; i++) {
total_score = 0;
for (int j = 0; j < 6; j++) {
total_score += scores[i][j];
}
avg_score = total_score / 6;
printf("第%d个学生的总成绩为:%.2f,平均成绩为:%.2f\n", i+1, total_score, avg_score);
}
return 0;
}
```
运行程序后,按照提示输入每个学生的成绩,程序会自动计算每个学生的总成绩和平均成绩,并输出在屏幕上。需要注意的是,由于涉及到小数,需要用`float`类型存储成绩。另外,`%.2f`表示输出两位小数的浮点数。