编辑代码

#include <stdio.h>

#define MAX_STUDENTS 100

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

int numStudents = 0;
Student students[MAX_STUDENTS];

void inputScores() {
    printf("Enter the number of students: ");
    scanf("%d", &numStudents);

    for (int i = 0; i < numStudents; i++) {
        printf("Enter name of student %d: ", i + 1);
        scanf("%s", students[i].name);

        printf("Enter score of student %d: ", i + 1);
        scanf("%d", &students[i].score);
    }
}

void displayScores() {
    printf("\nStudent Scores:\n");
    for (int i = 0; i < numStudents; i++) {
        printf("%s: %d\n", students[i].name, students[i].score);
    }
}

void calculateTotalAverage() {
    int total = 0;
    for (int i = 0; i < numStudents; i++) {
        total += students[i].score;
    }

    float average = (float)total / numStudents;
    printf("\nTotal Score: %d\n", total);
    printf("Average Score: %.2f\n", average);
}

void findMinMaxScore() {
    int maxScore = students[0].score;
    int minScore = students[0].score;

    for (int i = 1; i < numStudents; i++) {
        if (students[i].score > maxScore) {
            maxScore = students[i].score;
        }
        if (students[i].score < minScore) {
            minScore = students[i].score;
        }
    }

    printf("\nMaximum Score: %d\n", maxScore);
    printf("Minimum Score: %d\n", minScore);
}

void calculateGradeDistribution() {
    int gradeCount[5] = {0};

    for (int i = 0; i < numStudents; i++) {
        int score = students[i].score;
        if (score >= 90) {
            gradeCount[0]++;
        } else if (score >= 80) {
            gradeCount[1]++;
        } else if (score >= 70) {
            gradeCount[2]++;
        } else if (score >= 60) {
            gradeCount[3]++;
        } else {
            gradeCount[4]++;
        }
    }

    printf("\nGrade Distribution:\n");
    printf("A (90-100): %d students\n", gradeCount[0]);
    printf("B (80-89): %d students\n", gradeCount[1]);
    printf("C (70-79): %d students\n", gradeCount[2]);
    printf("D (60-69): %d students\n", gradeCount[3]);
    printf("F (0-59): %d students\n", gradeCount[4]);
}

int main() {
    int choice;

    do {
        printf("\nMenu:\n");
        printf("1. Input Student Scores\n");
        printf("2. Display Student Scores\n");
        printf("3. Calculate Total and Average Score\n");
        printf("4. Find Maximum and Minimum Score\n");
        printf("5. Calculate Grade Distribution\n");
        printf("6. Exit\n");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                inputScores();
                break;
            case 2:
                displayScores();
                break;
            case 3:
                calculateTotalAverage();
                break;
            case 4:
                findMinMaxScore();
                break;
            case 5:
                calculateGradeDistribution();
                break;
            case 6:
                printf("Exiting the system.\n");
                break;
            default:
                printf("Invalid choice. Please enter a valid option.\n");
        }
    } while (choice != 6);

    return 0;
}