We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
#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; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
#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;
}
The text was updated successfully, but these errors were encountered: