学生信息管理系统c语言
时间: 2023-06-30 20:08:25 浏览: 59
学生信息管理系统是一种常见的应用程序,可以用C语言来实现。以下是一个简单的学生信息管理系统的C语言程序示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
char name[50];
int age;
int id;
};
int main() {
struct student s[100];
int n, i, choice, id;
char ch;
printf("Enter the number of students: ");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("Enter the name of student %d: ", i+1);
scanf("%s", s[i].name);
printf("Enter the age of student %d: ", i+1);
scanf("%d", &s[i].age);
printf("Enter the id of student %d: ", i+1);
scanf("%d", &s[i].id);
}
do {
printf("\n1. Display all students\n");
printf("2. Search student by id\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
printf("\n%-20s%-10s%-10s\n", "Name", "Age", "ID");
for (i = 0; i < n; i++) {
printf("%-20s%-10d%-10d\n", s[i].name, s[i].age, s[i].id);
}
break;
case 2:
printf("Enter the id of the student to search: ");
scanf("%d", &id);
for (i = 0; i < n; i++) {
if (s[i].id == id) {
printf("\n%-20s%-10s%-10s\n", "Name", "Age", "ID");
printf("%-20s%-10d%-10d\n", s[i].name, s[i].age, s[i].id);
break;
}
}
if (i == n) {
printf("No student found with the id %d\n", id);
}
break;
case 3:
exit(0);
default:
printf("Invalid choice\n");
}
printf("\nDo you want to continue? (y/n): ");
scanf(" %c", &ch);
} while (ch == 'y' || ch == 'Y');
return 0;
}
```
该程序通过结构体来存储每个学生的姓名、年龄和ID。在程序开始时,用户输入学生数量,并在循环中输入每个学生的信息。然后,程序显示一个菜单,让用户选择要执行的操作。用户可以选择显示所有学生信息或按ID搜索学生。最后,程序询问用户是否要继续,如果用户选择是,则返回菜单,否则退出程序。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)