用C语言编写一个程序,输入某学生的三门课程考试成绩计算出该学生的总成绩和平均成绩并画出流程图,要求输出是平均成绩保留一位小数
时间: 2023-05-16 17:06:07 浏览: 149
好的,这是一个简单的程序,以下是代码和流程图:
```c
#include <stdio.h>
int main() {
float score1, score2, score3, total, average;
printf("请输入该学生的三门课程考试成绩:\n");
scanf("%f %f %f", &score1, &score2, &score3);
total = score1 + score2 + score3;
average = total / 3;
printf("该学生的总成绩为:%.1f,平均成绩为:%.1f\n", total, average);
return 0;
}
```
流程图:
```
开始
输入三门课程的成绩
计算总成绩
计算平均成绩
输出总成绩和平均成绩
结束
```
希望这个程序对你有帮助!
相关问题
用c语言编写:输入五个学生的三门课程成绩,求每个学生的平均成绩和每门课程的平均成绩
以下是一个用C语言编写的程序,可以实现输入五个学生的三门课程成绩,求每个学生的平均成绩和每门课程的平均成绩。这里假设每门课程的成绩都是一个整数。
```c
#include <stdio.h>
int main() {
int scores[5][3];
int i, j;
int student_sum[5] = {0};
int course_sum[3] = {0};
// 输入每个学生的三门课程成绩
for (i = 0; i < 5; i++) {
printf("请输入第%d个学生的三门课程成绩:\n", i+1);
for (j = 0; j < 3; j++) {
scanf("%d", &scores[i][j]);
student_sum[i] += scores[i][j];
course_sum[j] += scores[i][j];
}
}
// 输出每个学生的平均成绩
printf("每个学生的平均成绩:\n");
for (i = 0; i < 5; i++) {
printf("第%d个学生的平均成绩为:%.2f\n", i+1, (float)student_sum[i]/3);
}
// 输出每门课程的平均成绩
printf("每门课程的平均成绩:\n");
for (j = 0; j < 3; j++) {
printf("第%d门课程的平均成绩为:%.2f\n", j+1, (float)course_sum[j]/5);
}
return 0;
}
```
该程序首先定义了一个二维数组`scores`来存储每个学生的三门课程成绩,以及两个一维数组`student_sum`和`course_sum`,分别用于存储每个学生的总成绩和每门课程的总成绩。程序使用嵌套的循环来依次输入每个学生的三门课程成绩,并且累加每个学生的总成绩和每门课程的总成绩。最后,程序根据累加的数据计算并输出每个学生的平均成绩和每门课程的平均成绩。
c语言编写一个程序输入10个学生的学号姓名三门课程的成绩,求出所有同学成绩和总分最高的学生
好的,以下是一个简单的 C 语言程序,可以实现你的需求:
```c
#include <stdio.h>
#include <string.h>
struct student {
char id[20];
char name[20];
float score1;
float score2;
float score3;
float total_score;
};
int main() {
struct student stu[10];
int i, max_index;
float max_score = 0;
// 输入学生信息
for (i = 0; i < 10; i++) {
printf("请输入第%d个学生的学号:", i+1);
scanf("%s", stu[i].id);
printf("请输入第%d个学生的姓名:", i+1);
scanf("%s", stu[i].name);
printf("请输入第%d个学生的第一门课程成绩:", i+1);
scanf("%f", &stu[i].score1);
printf("请输入第%d个学生的第二门课程成绩:", i+1);
scanf("%f", &stu[i].score2);
printf("请输入第%d个学生的第三门课程成绩:", i+1);
scanf("%f", &stu[i].score3);
stu[i].total_score = stu[i].score1 + stu[i].score2 + stu[i].score3;
}
// 求总分最高的学生
for (i = 0; i < 10; i++) {
if (stu[i].total_score > max_score) {
max_score = stu[i].total_score;
max_index = i;
}
}
// 输出最高分学生的信息
printf("总分最高的学生是:\n");
printf("学号:%s\n", stu[max_index].id);
printf("姓名:%s\n", stu[max_index].name);
printf("第一门课程成绩:%.2f\n", stu[max_index].score1);
printf("第二门课程成绩:%.2f\n", stu[max_index].score2);
printf("第三门课程成绩:%.2f\n", stu[max_index].score3);
printf("总分:%.2f\n", stu[max_index].total_score);
return 0;
}
```
程序中定义了一个结构体 `student`,用来存储每个学生的信息,包括学号、姓名、三门课程的成绩和总分。程序先循环输入十个学生的信息,然后再循环求出总分最高的学生,最后输出该学生的信息即可。