数据结构数据结构学生信息表,C语言
时间: 2024-06-05 18:04:43 浏览: 5
数据结构是计算机科学中研究数据如何在计算机中存储和组织的学科。学生信息表可以看作是一个简单的数据结构,通常用来存储和管理学生的基本信息,如姓名、学号、年龄、性别、专业等。
在C语言中,我们可以使用结构体来定义一个学生信息表。下面是一个示例代码:
```
#include <stdio.h>
#include <string.h>
// 定义学生信息结构体
struct student {
char name[20]; // 姓名
int id; // 学号
int age; // 年龄
char gender; // 性别
char major[20]; // 专业
};
int main() {
struct student stu1, stu2;
// 输入学生1的信息
printf("请输入学生1的信息:\n");
printf("姓名:");
scanf("%s", stu1.name);
printf("学号:");
scanf("%d", &stu1.id);
printf("年龄:");
scanf("%d", &stu1.age);
printf("性别:");
scanf(" %c", &stu1.gender);
printf("专业:");
scanf("%s", stu1.major);
// 输入学生2的信息
printf("请输入学生2的信息:\n");
printf("姓名:");
scanf("%s", stu2.name);
printf("学号:");
scanf("%d", &stu2.id);
printf("年龄:");
scanf("%d", &stu2.age);
printf("性别:");
scanf(" %c", &stu2.gender);
printf("专业:");
scanf("%s", stu2.major);
// 输出学生信息
printf("\n学生1的信息:\n");
printf("姓名:%s\n", stu1.name);
printf("学号:%d\n", stu1.id);
printf("年龄:%d\n", stu1.age);
printf("性别:%c\n", stu1.gender);
printf("专业:%s\n", stu1.major);
printf("\n学生2的信息:\n");
printf("姓名:%s\n", stu2.name);
printf("学号:%d\n", stu2.id);
printf("年龄:%d\n", stu2.age);
printf("性别:%c\n", stu2.gender);
printf("专业:%s\n", stu2.major);
return 0;
}
```
在上面的代码中,我们定义了一个名为`student`的结构体,并创建了两个`student`类型的变量`stu1`和`stu2`,分别表示两个学生的信息。然后通过`scanf()`函数输入每个学生的信息,最后通过`printf()`函数输出每个学生的信息。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)