#include <stdio.h>
#include <stdlib.h>
#define STU_NUM 10
struct student
{
char stu_id[20];
float score[3];
float total;
float aver;
};
void SortScore(student *stu,int n)
{
student stud;
for(int i = 0; i < n-1; i++)
for(int j = i+1 ; j < n; j++)
{
if(stu[i].total < stu[j].total)
{
stud = stu[i];
stu[i] = stu[j];
stu[j] = stud;
}
}
}
int main( )
{
student stu[STU_NUM];
for(int i = 0; i<STU_NUM; i++)
{
printf("请输入第%d个学生的学号:",i+1);
scanf("%s",&stu[i].stu_id);
printf("输入第%d个学生的数学成绩:",i+1);
scanf("%f",&stu[i].score[0]);
printf("输入第%d个学生的英语成绩:",i+1);
scanf("%f",&stu[i].score[1]);
printf("输入第%d个学生的计算机成绩:",i+1);
scanf("%f",&stu[i].score[2]);
stu[i].total = stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
stu[i].aver = stu[i].total/3;
}
printf("\n");
SortScore(stu,STU_NUM);
for(i = 0 ; i < STU_NUM; i++)
{
printf("序号: %d\t",i);
printf("学号:%s\t",stu[i].stu_id);
printf("数学:%f\t",stu[i].score[0]);
printf("英语:%f\t",stu[i].score[1]);
printf("计算机:%f\t",stu[i].score[2]);
printf("平均成绩:%f\t",stu[i].aver);
printf("总分:%f\t",stu[i].total);
printf("\n\n");
}
return 0;
}
#define STU_NUM 10
struct student
{
char stu_id[20];
float score[3];
float total;
float aver;
}
麻烦 给我发个完整的 我不会弄 谢谢啦
还是不行啊 还是运行不了
追答#include
#include
#define STU_NUM 3
struct student
{
char stu_id[20];
float score[3];
float total;
float aver;
};
void SortScore(student *stu,int n)
{
student stud;
for(int i = 0; i < n-1; i++)
for(int j = i+1 ; j < n; j++)
{
if(stu[i].total < stu[j].total)
{
stud = stu[i];
stu[i] = stu[j];
stu[j] = stud;
}
}
}
int main( )
{
student stu[STU_NUM];
for(int i = 0; i<STU_NUM; i++)
{
printf("请输入第%d个学生的学号:",i+1);
scanf("%s",stu[i].stu_id); //WARN
printf("输入第%d个学生的数学成绩:",i+1);
scanf("%f",&stu[i].score[0]);
printf("输入第%d个学生的英语成绩:",i+1);
scanf("%f",&stu[i].score[1]);
printf("输入第%d个学生的计算机成绩:",i+1);
scanf("%f",&stu[i].score[2]);
stu[i].total = stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
stu[i].aver = stu[i].total/3;
}
printf("\n");
SortScore(stu,STU_NUM);
for(int i = 0 ; i < STU_NUM; i++)
{
printf("序号: %d ",i);
printf("学号:%s ",stu[i].stu_id);
printf("数学:%.2f ",stu[i].score[0]);
printf("英语:%.2f ",stu[i].score[1]);
printf("计算机:%.2f ",stu[i].score[2]);
printf("平均成绩:%.2f ",stu[i].aver);
printf("总分:%.2f ",stu[i].total);
printf("\n\n");
}
return 0;
}
还是有一个错误啊
for(int i=0 ; i < STU_NUM; i++)
error C2374: 'i' : redefinition; multiple initialization
SortScore(stu,STU_NUM);
for( i = 0 ; i < STU_NUM; i++) //这里的int去掉
哪里??我改了 不行