成绩录入
上一篇 /
下一篇 2013-03-22 14:52:21
/ 个人分类:其它
#include<stdio.h>
struct Student
{
int no;
char name[15];
int score[3];
float ave;
};
struct Student stu[50];
struct Student input();
void display ( struct Student stud[],int count);
void mysort(struct Student stud[],int count);
void main()
{
int count=0;
char ch='y';
printf("请输入学员的信息:\n");
while((ch=='y')||(ch=='y'))
{
stu[count]=input();
count++;
printf("\n是否继续输入?(y\n):");
scanf(" %c",&ch);
}
printf("\n排序前的成绩如下:");
display(stu,count);
printf("\n排序后的成绩如下:");
mysort(stu,count);
display(stu,count);
}
struct Student input()
{
int i,sum=0;
struct Student studn;
printf("\n请输入学员的学号:");
scanf("%d",&studn.no);
printf("\n请输入学员的姓名:");
scanf("%s",studn.name);
printf("\n请输入学员的三门成绩:");
scanf("%n",&studn.score);
for(i=0;i<3;i++)
{
printf("第%d门成绩:",i+1);
scanf("%d",&studn.score
);
sum+=studn.score;
}
studn.ave=sum/3;
return studn;
}
void display(struct Student stud[],int count)
{
int i;
printf("\n学号\t姓名\t平均成绩");
for(i=0;i<count;i++)
{
printf("\n%d\t%s\t%4.1f",stud.no,stud.name,stud.ave);
}
}
void mysort(struct Student stud[],int count)
{
int i,j;
struct Student temp;
for(i=0;i<count;i++)
{
for(j=0;j<count-i-1;j++)
{
if(stud[j].ave<stud[j+1].ave)
{
temp=stud[j];
stud[j]=stud[j+1];
stu[j+1]=temp;
}
}
}
}
收藏
举报
TAG: