用c语言写个程序:按学号查找某名学生三门课程成绩并显示出来
时间: 2024-02-17 20:04:13 浏览: 180
好的,以下是一份用 C 语言编写的程序,可以按照学号查找某名学生的三门课程成绩并输出:
```c
#include <stdio.h>
#include <string.h>
// 定义学生结构体
struct Student {
char id[20]; // 学号
char name[20]; // 姓名
float score1; // 第一门课程成绩
float score2; // 第二门课程成绩
float score3; // 第三门课程成绩
};
// 定义全局变量,存储学生信息
struct Student students[] = {
{"001", "张三", 80, 85, 90},
{"002", "李四", 75, 78, 80},
{"003", "王五", 90, 92, 88},
{"004", "赵六", 85, 80, 90},
{"005", "钱七", 82, 88, 85}
};
int main() {
char id[20];
printf("请输入学生学号:");
scanf("%s", id);
int i;
for (i = 0; i < 5; i++) {
if (strcmp(students[i].id, id) == 0) {
printf("学号:%s\n", students[i].id);
printf("姓名:%s\n", students[i].name);
printf("第一门课程成绩:%.2f\n", students[i].score1);
printf("第二门课程成绩:%.2f\n", students[i].score2);
printf("第三门课程成绩:%.2f\n", students[i].score3);
break;
}
}
if (i == 5) {
printf("未找到该学生信息。\n");
}
return 0;
}
```
可以根据实际需求修改学生信息和查询方式。
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.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://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)