QZHY-HTX / Data-Structure

泉州海洋职业学院信息工程学院2023-2024学年第二学期数据结构课程仓库
MIT License
6 stars 9 forks source link

陈文鑫+2302580042 #37

Open wscjdsb opened 7 months ago

wscjdsb commented 7 months ago
#include<stdio.h>
struct stu
{
    char id[20];
    float score;
};
int main(){
    struct stu student[5] ={
        {"10001",98},{"10002",83},{"10003",44},{"10004",34},{"10005",67}
    };
    const int n = 5; 
    struct stu temp;
    int i,j,k;
    for(i = 0;i<n-1;i++){
        k = i;
        for(j = i + 1;j<n;j++){
            if(student[j].score > student[k].score)
            k = j;
            temp = student[k];
            student[k] = student[i];
            student[i] = temp;
        }
    }

    float avg,sum; 
    int lower_stu_num = 0;
    for(i = 0;i<n;i++){
        sum += student[i].score;
        if(student[i].score <=60.0)
            lower_stu_num +=1;
        } 
    avg = sum / n;

    for(i = 0;i<n;i++)
        printf("%s %.2f\n",student[i].id,student[i].score);
    printf("%.2f %d",avg,lower_stu_num);
    return 0;
}