该楼层疑似违规已被系统折叠隐藏此楼查看此楼
#include
struct Stu
{
char name[20];
int Xuehao;
float Chinese;
float Math;
float English;
float all;
}student[5];
/*
*/
struct Stu student[];
void TolCom(student)
{
struct Stu tem;
int i,j;
float total1,total2;
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
total1=student[i].all;
total2=student[j].all;
if (total1 > total2)
{
tem = student[i];
student[i] = student[j];
student[j] = tem;
}
}
}
}
/*
*/
void GraDec(float i1)
{
for(;;)
{
if(i1<0||i1>100)
{
printf("illegal\n");
printf("please input it again\n");
fflush(stdin);
scanf("%f",&i1);
continue;
}
break;
}
}
void main()
{
int i;
float i1;
for(i=0;i<5;i++)
{
printf("the information of NO.%d\n",i+1);
printf("please input name\n");
scanf("%s",&student[i].name);
printf("%s\n",student[i].name);
printf("please input xuehao\n");
scanf("%d",&student[i].Xuehao);
printf("please input chinese scores\n");
scanf("%f",&i1);
GraDec( i1);
student[i].Chinese=i1;
printf("please input english scores\n");
scanf("%f",&i1);
GraDec( i1);
student[i].English=i1;
printf("please input Math scores\n");
scanf("%f",&i1);
GraDec( i1);
student[i].Math=i1;
}
printf("%f",student[2].Chinese);
printf("***********************未排序总成绩如下**************\n");
for(i=0;i<5;i++)
{
printf("the TOTAL score of NO.%d\t",i);
student[i].all=student[i].Math+student[i].Chinese+student[i].English;
printf("%f\n",student[i].all);
}
TolCom(student);
printf("*******************排序结果如下***********************\n");
for(i=0;i<5;i++)
{
printf("%d\t %f\n",i,student[i].all);
}
}
如果觉得《c语言结构体函数如何调用 分函数的引用问题 如何调用结构体》对你有帮助,请点赞、收藏,并留下你的观点哦!