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

2302580043陈禧忠 #64

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

2302580043陈禧忠 #64

baikaishui55 opened this issue Mar 12, 2024 · 0 comments

Comments

@baikaishui55
Copy link

#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; ////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;  //avg:平均数;sum:临时总数
    int lower_stu_num = 0;   //lower_stu_num:不及格人数
    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;
}

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