要實(shí)現(xiàn)一個(gè)C語言成績查詢系統(tǒng),你可以按照以下步驟進(jìn)行:
typedef struct {
int studentID;
char name[50];
float score;
} Student;
Student student;
printf("請輸入學(xué)生信息:\n");
printf("學(xué)號:");
scanf("%d", &student.studentID);
printf("姓名:");
scanf("%s", student.name);
printf("成績:");
scanf("%f", &student.score);
Student students[100];
int numStudents = 0;
students[numStudents++] = student;
int searchStudentByID(int studentID) {
for (int i = 0; i < numStudents; i++) {
if (students[i].studentID == studentID)
return i;
}
return -1;
}
int searchStudentByName(char *name) {
for (int i = 0; i < numStudents; i++) {
if (strcmp(students[i].name, name) == 0)
return i;
}
return -1;
}
int index = searchStudentByID(123456);
if (index != -1) {
printf("學(xué)號:%d\n", students[index].studentID);
printf("姓名:%s\n", students[index].name);
printf("成績:%.2f\n", students[index].score);
} else {
printf("未找到該學(xué)生。\n");
}
以上是一個(gè)簡單的C語言成績查詢系統(tǒng)的實(shí)現(xiàn)示例,你可以根據(jù)需要進(jìn)行修改和擴(kuò)展。