Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

孙谙炫2302580056 #62

Open
sunanxuan opened this issue Mar 12, 2024 · 0 comments
Open

孙谙炫2302580056 #62

sunanxuan opened this issue Mar 12, 2024 · 0 comments

Comments

@sunanxuan
Copy link

#include <stdio.h>
#include <stdlib.h>
strucu student {
int id;
int score;
}
void swap(struct student *a,struct student *b){
struct student temp=*a;
*a=*b;
*b=temp;
}
void bubblesort(struct student arr[],int n){
int i,j;
for(i=0;j<n-i-1;j++){
if(arr[j].score>arr[j+1],score){
swap(&arr[j],&arr[j+1]);
}
}
}
void calculateStatistics(struct Student arr[], int n) {
int failCount = 0;
int totalScore = 0;

for (int i = 0; i < n; i++) {
    totalScore += arr[i].score;

    if (arr[i].score < 60) {
        failCount++;
    }
}

if (n != 0) {
    printf("平均成绩: %.2f\n", (float)totalScore / n);
} else {
    printf("没有学生成绩\n");
}

printf("不及格人数: %d\n", failCount);

}
int main() {
int n;
printf("请输入学生人数: ");
scanf("%d", &n);

struct Student *students = (struct Student *)malloc(n * sizeof(struct Student));
printf("请输入学生学号和成绩:\n");

for (int i = 0; i < n; i++) {
    printf("学号: ");
    scanf("%d", &students[i].id);

    printf("成绩: ");
    scanf("%d", &students[i].score);
}

bubbleSort(students, n);
printf("按成绩从高到低排序的学生学号和成绩:\n");

for (int i = 0; i < n; i++) {
    printf("学号: %d, 成绩: %d\n", students[i].id, students[i].score);
}

calculateStatistics(students, n);
free(students);
return 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant