用C语言先输入一个整数n表示有n个学生信息。(假设学生最多有50人) 接着输入这n个学生的学号、姓名(不超过20个字符,可能带空格)、性别、3门课程成绩。然后再输入一个待查找的学号。若存在该学号的学生,输出这个学生的所有信息.若不存在,则输出 "Not Found"(不包括引号)
时间: 2024-03-02 22:53:49 浏览: 23
好的,这里是一个用 C 语言实现的程序,可以实现你的要求:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 50
#define MAX_NAME_LEN 20
struct Student {
int id;
char name[MAX_NAME_LEN + 1];
char gender;
int score1, score2, score3;
};
int main() {
struct Student students[MAX_STUDENTS];
int n, i, id;
// 输入学生信息
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &students[i].id);
scanf("%s", students[i].name);
scanf(" %c", &students[i].gender);
scanf("%d%d%d", &students[i].score1, &students[i].score2, &students[i].score3);
}
// 输入待查找的学号
scanf("%d", &id);
// 查找学生信息
for (i = 0; i < n; i++) {
if (students[i].id == id) {
printf("ID: %d\n", students[i].id);
printf("Name: %s\n", students[i].name);
printf("Gender: %c\n", students[i].gender);
printf("Score1: %d\n", students[i].score1);
printf("Score2: %d\n", students[i].score2);
printf("Score3: %d\n", students[i].score3);
return 0;
}
}
printf("Not Found\n");
return 0;
}
```
这个程序首先定义了一个结构体 `Student`,包含学号、姓名、性别、3门课程成绩。然后定义了一个数组 `students`,用来存储所有学生的信息。
程序接受一个整数 `n`,表示有 `n` 个学生信息。然后依次输入每个学生的信息。最后输入一个待查找的学号。
程序会遍历整个学生数组,查找是否存在该学号的学生。如果存在,就输出该学生的全部信息;如果不存在,则输出 Not Found。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)