#include <stdio.h>
int count=0;
struct student
{
int num;
char name[20];
float score[3];
float pscore;
};
struct student stu[50];
void st(struct student *p)
{
int i;
float sum=0;
printf(“\n学号: “);
scanf(“%d”,&p->num);
printf(“\n姓名: “);
fflush(stdin);
gets(p->name);
printf(“三门成绩:\n”);
for (i=0;i<3;i++)
{
printf(“成绩%d: “,i+1);
scanf(“%f”,&p->score[i]);
sum+=p->score[i];
printf(“\n”);
}
p->pscore =sum/3;
}
void paixu(struct student stu[],int count);
void put(struct student stu[],int count);
void charu(struct student stu[],int count);
void shanchu(struct student stu[],int count);
//主函数
void main()
{
int i=0;
char k=’y';
int count=0;
do
{
st(&stu[i]);
i++;
count++;
printf(“你是否继续输入(y/n)”);
fflush(stdin);
scanf(“%c”,&k);
}while(k==’y'||k==’Y');
printf(“排序前的的学员信息如下:”);
put(stu,count);
printf(“排序后的学员成绩信息如下:”);
paixu(stu,count);
put(stu,count);
charu(stu,count);
put(stu,count);
shanchu(stu,count);
put(stu,count);
}
void paixu(struct student stu[],int count)
{
struct student t;
int i,j;
for (i=0;i<count-1;i++)
for (j=0;j<count-i-1;j++)
{
if (stu[i].pscore<stu[j+1].pscore)
t=stu[i];
stu[i]=stu[j+1];
stu[j+1]=t;
}
}
void put(struct student stu[50],int count)
{
int i;
printf(“\n\t学号\t姓名\t平均成绩”);
for (i=0;i<count;i++)
{
printf(“\n\t%-03d”,stu[i].num);
printf(“\t%-15s”,stu[i].name);
printf(“\t%-10.1f\n”,stu[i].pscore);
}
}
//实现插入功能
void charu(struct student stu[50],int count)
{
int i,j;
float temp;
printf(“\n请输入要插入的学员成绩”);
st(&stu[count+1]);
temp=stu[count+1].pscore;
for (i=0;i<count;i++)
{
if (stu[count].pscore<temp)
break;
}
for (j=count;j>=i;j–)
{
stu[j+1]=stu[i];
}
stu[i].pscore=temp;
}
/*实现删除功能*/
void shanchu(struct student stu[50],int count)
{
int i,j;
int date;
printf(“\n请输入要删除的学生的学号:”);
scanf(“%d”,&date);
for (i=0;i<count;i++)
{
if (stu[i].num==date)
break;
}
for (j=i;j<count-1;j++)
{
stu[j]=stu[j+1];
}
}
插入和删除功能运行不起来
哪个高手帮我改改??????????
>> 本文固定链接: http://www.vcgood.com/archives/2091
>> 转载请注明: yanbinvschengxu 2008年01月14日 于 C语言帝国 发表