c语言写学生信息管理系统
时间: 2023-05-20 12:05:25 浏览: 49
非常感谢您的提问,以下是一个简单的 C 语言学生信息管理系统的代码示例:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
typedef struct {
char name[50];
int age;
float gpa;
} Student;
int main() {
Student students[MAX_STUDENTS];
int num_students = 0;
while (1) {
printf("请选择操作:\n");
printf("1. 添加学生信息\n");
printf("2. 显示所有学生信息\n");
printf("3. 退出程序\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
if (num_students >= MAX_STUDENTS) {
printf("学生信息已满,无法添加!\n");
} else {
printf("请输入学生姓名:");
scanf("%s", students[num_students].name);
printf("请输入学生年龄:");
scanf("%d", &students[num_students].age);
printf("请输入学生GPA:");
scanf("%f", &students[num_students].gpa);
num_students++;
printf("学生信息添加成功!\n");
}
break;
case 2:
printf("所有学生信息如下:\n");
for (int i = 0; i < num_students; i++) {
printf("姓名:%s,年龄:%d,GPA:%f\n", students[i].name, students[i].age, students[i].gpa);
}
break;
case 3:
printf("程序已退出!\n");
exit(0);
default:
printf("无效的选择,请重新输入!\n");
break;
}
}
return 0;
}
希望这个代码示例能够帮助您!
相关推荐
![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)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)