c语言

基于C语言实现简单学生成绩管理系统

小亿
88
2024-03-08 15:36:23
栏目: 编程语言

#include <stdio.h>

#define MAX_STUDENTS 100

struct Student { int id; char name[50]; float score; };

int main() { struct Student students[MAX_STUDENTS]; int num_students = 0;

printf("Enter the number of students: ");
scanf("%d", &num_students);

if (num_students > MAX_STUDENTS) {
    printf("Exceeds maximum number of students.\n");
    return 1;
}

for (int i = 0; i < num_students; i++) {
    printf("Enter student ID: ");
    scanf("%d", &students[i].id);

    printf("Enter student name: ");
    scanf("%s", students[i].name);

    printf("Enter student score: ");
    scanf("%f", &students[i].score);
}

printf("\nStudent Information:\n");
printf("ID\tName\tScore\n");

for (int i = 0; i < num_students; i++) {
    printf("%d\t%s\t%.2f\n", students[i].id, students[i].name, students[i].score);
}

return 0;

}

0
看了该问题的人还看了