嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
本程序用于学生成绩管理,输入学生人数,成绩,并进行排序
核心代码://函数功能:输入学生信息
void InputStudent(struct Student *pst,int len)
{
int i;
for(i=0;i<len; i)
{
printf("请输入第%d个学生的信息:\n",i 1);
printf("age = ");
scanf("%d",&pst[i].age);
printf("name = ");
scanf("%s",pst[i].name);
printf("score = ");
scanf("%f",&pst[i].score);
}
}
//函数功能:冒泡算法实现成绩升序排列
void sort(struct Student *pst,int len)
{
int i,j;
struct Student t;
for(i=0;i<len-1; i)
{
for(j=0;j<len-1-i; j)
{
if(pst[j].score>pst[j 1].score)
{
t = pst[j];
pst[j] = pst[j 1];
pst[j 1] = t;
}
}
}
printf("\n\n学生的信息是:\n");
}
//函数功能:输出排序后的学生信息
void OutputStudent(struct Student *pst,int len)
{
int i;
for(i=0;i<len; i)
{
printf("第%d个学生的信息是:\n",i 1);
printf("age = %d\n",pst[i].age);
printf("name = %s\n",pst[i].name);
printf("score = %f\n",pst[i].score);
printf("\n");
}
}
int main(void)
{
int len;
struct Student *pArr;
printf("请输入学生的个数:\n");
printf("len = ");
scanf("%d",&len);
pArr = (struct Student *)malloc(len * sizeof(struct Student));
InputStudent(pArr,len);
sort(pArr,len);
OutputStudent(pArr,len);
return 0;
}