请用c语言实现学生成绩管理系统
时间: 2023-05-18 12:03:02 浏览: 122
好的,以下是一个简单的学生成绩管理系统的 C 语言代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct student {
char name[50];
int id;
float grade;
};
struct student students[MAX_STUDENTS];
int num_students = 0;
void add_student() {
if (num_students >= MAX_STUDENTS) {
printf("Error: too many students\n");
return;
}
struct student s;
printf("Enter student name: ");
scanf("%s", s.name);
printf("Enter student ID: ");
scanf("%d", &s.id);
printf("Enter student grade: ");
scanf("%f", &s.grade);
students[num_students++] = s;
}
void print_students() {
printf("Name\tID\tGrade\n");
for (int i = 0; i < num_students; i++) {
printf("%s\t%d\t%.2f\n", students[i].name, students[i].id, students[i].grade);
}
}
int main() {
while (1) {
printf("1. Add student\n");
printf("2. Print students\n");
printf("3. Exit\n");
printf("Enter choice: ");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
print_students();
break;
case 3:
exit(0);
default:
printf("Invalid choice\n");
}
}
return 0;
}
希望这个代码能够帮到你!
阅读全文