补全下段代码:#include <stdio.h> struct student { int num; char name[15]; float score[3]; float sum; }; void calc(struct student *p,int n); void sort(struct student *p,int n); int main() { struct student stu[5]; int i,j; float f; for(i=0;i<5;i++) { scanf("%d%s",&stu[i].num,stu[i].name); for(j=0;j<3;j++) { scanf("%f",&f); stu[i].score[j]=f; } } calc(stu,5); sort(stu,5); for(i=0;i<5;i++) { printf("%5d%15s",stu[i].num,stu[i].name); printf(" %.1f %.1f %.1f %.1f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2], stu[i].sum); } return 0;
时间: 2024-04-28 14:21:56 浏览: 83
学习C语言必会的7组代码基础代码学习.rar
}void calc(struct student *p, int n) {
int i, j;
for (i = 0; i < n; i++) {
p[i].sum = 0;
for (j = 0; j < 3; j++) {
p[i].sum += p[i].score[j];
}
}
}
void sort(struct student *p, int n) {
int i, j;
struct student temp;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1 - i; j++) {
if (p[j].sum < p[j + 1].sum) {
temp = p[j];
p[j] = p[j + 1];
p[j + 1] = temp;
}
}
}
}
阅读全文