学生信息系统结构体代码
时间: 2023-07-13 13:41:06 浏览: 78
好的,以下是一个简单的学生信息系统的结构体代码示例:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100
typedef struct {
int id;
char name[50];
int age;
float gpa;
} Student;
int main() {
Student students[MAX_STUDENTS];
int num_students = 0;
// 添加学生
students[num_students].id = 1001;
strcpy(students[num_students].name, "张三");
students[num_students].age = 18;
students[num_students].gpa = 3.8;
num_students++;
students[num_students].id = 1002;
strcpy(students[num_students].name, "李四");
students[num_students].age = 19;
students[num_students].gpa = 3.6;
num_students++;
// 输出学生信息
for (int i = 0; i < num_students; i++) {
printf("学号:%d,姓名:%s,年龄:%d,GPA:%f\n", students[i].id, students[i].name, students[i].age, students[i].gpa);
}
return 0;
}
```
该代码定义了一个 `Student` 结构体,包含学生的学号、姓名、年龄与 GPA 等信息。使用一个数组 `students` 来保存多个学生的信息。通过循环遍历这个数组并输出每个学生的信息。
当然,这只是一个简单的示例,实际的学生信息系统可能会更加复杂,需要根据具体的需求进行设计。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)