成绩统计 分数 5 作者 王从银 单位 吉首大学 输入一个考试成绩的序列,以-1为结束标记。成绩均为整数,且在0到100之间。序列长度在1到1000之间。计算并输出最高、最低和平均成绩。 输入举例:
时间: 2024-06-14 13:06:00 浏览: 20
以下是计算最高、最低和平均成绩的Python代码示例:
```python
scores = []
while True:
score = int(input("请输入一个考试成绩(输入-1结束):"))
if score == -1:
break
scores.append(score)
max_score = max(scores)
min_score = min(scores)
avg_score = sum(scores) / len(scores)
print("最高成绩:", max_score)
print("最低成绩:", min_score)
print("平均成绩:", round(avg_score, 2))
```
相关问题
C语言成绩统计 分数 5 作者 王从银 单位 吉首大学 输入一个考试成绩的序列,以-1为结束标记。成绩均为整数,且在0到100之间。序列长度在1到1000之间。计算并输出最高、最低和平均成绩。 输入举例:
根据提供的引用内容,以下是一个C语言的成绩统计的示例代码:
```c
#include <stdio.h>
int main() {
int scores[1000];
int num = 0;
int max_score = 0;
int min_score = 100;
int sum = 0;
int count = 0;
int score;
// 输入成绩序列
while (1) {
scanf("%d", &score);
if (score == -1) {
break;
}
scores[num] = score;
num++;
}
// 计算最高、最低和平均成绩
for (int i = 0; i < num; i++) {
if (scores[i] > max_score) {
max_score = scores[i];
}
if (scores[i] < min_score) {
min_score = scores[i];
}
sum += scores[i];
count++;
}
// 输出结果
printf("最高成绩:%d\n", max_score);
printf("最低成绩:%d\n", min_score);
printf("平均成绩:%.2f\n", (float)sum / count);
return 0;
}
```
6-1 计算总分 分数 10 作者 王从银 单位 吉首大学 请编写一个函数sum,函数的功能是:计算一个由结构体表示的包含多门课程成绩组成的学生的总成绩。 函数接口定义: double sumScore(struct student stu); 其中 stu是用户传入的参数。函数须返回学生的总成绩。 裁判测试程序样例: #include <stdio.h> struct student{ int sid; char name[20]; double math; //此数据成员表示数学程成绩 double english; //此数据成员表示英语课程成绩 double program; //此数据成员表示编程课程成绩 }; double sum(struct student st); int main(){ struct student st; scanf("%d%s%lf%lf%lf",&st.sid, st.name, &st.math, &st.english, &st.program); printf("%.2f\n",sum(st)); return 0; } /* 请在这里填写答案 */ 输入样例: 1000 xiaopeng 90 90 90 输出样例: 270.00 代码长度限制 16 KB 时间限制 400 ms 内存限制 64 MC语言
本题需要计算一个学生的总成绩,所以我们需要将该学生各科目的成绩相加。可以编写如下的函数实现:
```c
double sumScore(struct student stu) {
return stu.math + stu.english + stu.program;
}
```
其中,`stu.math`、`stu.english` 和 `stu.program` 分别表示数学、英语和编程课程的成绩。函数返回这三个成绩的和。
完整代码如下:
```c
#include <stdio.h>
struct student {
int sid;
char name[20];
double math; // 数学成绩
double english; // 英语成绩
double program; // 编程成绩
};
double sumScore(struct student stu) {
return stu.math + stu.english + stu.program;
}
int main() {
struct student st;
scanf("%d%s%lf%lf%lf", &st.sid, st.name, &st.math, &st.english, &st.program);
printf("%.2f\n", sumScore(st));
return 0;
}
```