用C语言写一个创建学生表(包括学号,姓名,性别,生日,班级)算法
时间: 2023-05-29 07:06:32 浏览: 248
定义一个包含学生信息(学号,姓名,成绩)的顺序表
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
typedef struct {
char id[10];
char name[20];
char gender[5];
char birthday[20];
char class[20];
} Student;
int main() {
Student students[MAX_STUDENTS];
int count = 0;
while (count < MAX_STUDENTS) {
printf("请输入第%d个学生的信息:\n", count + 1);
printf("学号:");
scanf("%s", students[count].id);
if (strcmp(students[count].id, "exit") == 0) {
break;
}
printf("姓名:");
scanf("%s", students[count].name);
printf("性别:");
scanf("%s", students[count].gender);
printf("生日:");
scanf("%s", students[count].birthday);
printf("班级:");
scanf("%s", students[count].class);
count++;
}
printf("学生表如下:\n");
printf("学号\t姓名\t性别\t生日\t班级\n");
for (int i = 0; i < count; i++) {
printf("%s\t%s\t%s\t%s\t%s\n", students[i].id, students[i].name, students[i].gender, students[i].birthday, students[i].class);
}
return 0;
}
阅读全文