QZHY-HTX / Data-Structure

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

雷成宇+2302580011 #38

Open AzimoFZO opened 7 months ago

AzimoFZO commented 7 months ago

include

// 定义结构体 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; }