写出一个程序,要求:输入学生姓名、平时成绩、期末成绩、平时成绩和期末成绩的百分比,计算综合成绩
时间: 2023-02-23 19:32:34 浏览: 134
程序如下: #输入学生姓名
name = input('请输入学生姓名:')#输入平时成绩
score_1 = float(input('请输入平时成绩:'))#输入期末成绩
score_2 = float(input('请输入期末成绩:'))#输入平时成绩和期末成绩的百分比
percentage = float(input('请输入平时成绩和期末成绩的百分比:'))#计算综合成绩
total_score = score_1 * (1 - percentage/100) + score_2 * (percentage/100)#输出综合成绩
print('{}的综合成绩为:{:.2f}'.format(name, total_score))
相关问题
输入学生姓名、平时成绩、期末成绩、平时成绩和期末成绩的百分比,计算综合成绩
可以使用以下公式计算学生的综合成绩:
综合成绩 = 平时成绩 × 平时成绩百分比 + 期末成绩 × 期末成绩百分比
其中,平时成绩百分比和期末成绩百分比的和应该为100%。
例如,如果一个学生的姓名为张三,平时成绩为80分,期末成绩为90分,平时成绩百分比为30%,期末成绩百分比为70%,那么他的综合成绩就是:
综合成绩 = 80 × .3 + 90 × .7 = 86 分
这个学生的综合成绩为86分。
写一段c语言代码,调用search函数,输入学号,查询学生平时成绩和期末成绩
好的,以下是一段简单的C语言代码,可以调用search()函数查询学生的平时成绩和期末成绩:
```c
#include <stdio.h>
#include <string.h>
// 定义学生结构体
struct Student {
char name[20];
int id;
float score1; // 平时成绩
float score2; // 期末成绩
};
// 定义search函数
void search(struct Student stu[], int n, int id) {
int i;
for (i = 0; i < n; i++) {
if (stu[i].id == id) {
printf("%s的平时成绩是%.2f,期末成绩是%.2f。\n", stu[i].name, stu[i].score1, stu[i].score2);
return;
}
}
printf("没有找到学号为%d的学生。\n", id);
}
int main() {
// 定义学生数组
struct Student stu[] = {
{"张三", 1001, 80, 85.5},
{"李四", 1002, 70, 90},
{"王五", 1003, 85.5, 75},
{"赵六", 1004, 90, 80},
{"钱七", 1005, 78, 92}
};
int n = sizeof(stu) / sizeof(stu[0]); // 计算学生数组长度
int id;
printf("请输入要查询的学生学号:");
scanf("%d", &id);
search(stu, n, id); // 调用search函数查询学生平时成绩和期末成绩
return 0;
}
```
运行程序后,输入要查询的学生学号即可查询该学生的平时成绩和期末成绩。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![asm](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)