1、
li 45 300.0
chang 30 200.0
chang
2、
#include
struct students
{
char sid[100];
char name[100];
float score[3];
}student;
void main()
{ int i; float j;
printf("\nPlease input sid: ");
scanf("%s",student.sid);
printf("\nPlease input name: ");
scanf("%s",http://doc.wendoc.com);
printf("\nPlease input 3 score:(like1,1,1) ");/*输入逗号隔开*/
scanf("%f,%f,%f",&student.score[0],&student.score[1],&student.score[2]);
printf("\nsid = %s",student.sid);
printf("\nname = %s",http://doc.wendoc.com);
j=(student.score[0]+student.score[1]+student.score[2])/3.0;
printf("\naverage = %.2f",j);
getch();
}
3、
#include
#include
#define F sizeof(student)
#define NULL 0
typedef struct scores
{int english;
int math;
int c_language;
int all;
}TP;
typedef struct students
{char sid[15];
char name[15];
TP score;
struct students *next;
}student;
student *input()
{student *head,*p1,*p2;
int n=0; char ch;
clrscr();
head=(student *)malloc(F);head->next=NULL;
do
{ n++;
printf("\n\nPlease input %d student message: \n\n",n);
printf("\t%d student sid: ",n);
p1=(student *)malloc(F);p1->next=NULL;
scanf("%s",p1->sid);
printf("\n\t%d student name: ",n);
scanf("%s",p1->name);
printf("\n\t%d student scores(englesh,math,c_language): ",n);
scanf("%d,%d,%d",&p1->score.english,&p1->score.math,&p1->score.c_language);
p1->score.all=p1->score.english+p1->score.math+p1->score.c_language;
if(n==1)
{head->next=p1;p2=p1; }
else
{p2->next=p1;
p2=p1;
}
printf("\n\n\t\t\tContinue or back (press y/n): ");
ch=getch();
}while(ch=='y'||ch=='Y');
return head;
}
void average1(student *head)
{student *p; int j;
clrscr();
p=head->next;
while(p)
{j=p->score.all/3;
printf("\n\nname: %s\taverage: %d",p->name,j);
p=p->next;
}
printf("\n\n\nPress eny key return.");
getch();
}
void average2(student *head)
{
student *p;int n=0,temp1=0,temp2=0,temp3=0;
p=head->next;
while(p)
{temp1+=p->score.english;
temp2+=p->score.math;
temp3+=p->score.c_language;
p=p->next;n++;
}
printf("\n\naverage english is : %d\naverage math is : %d\naverage c_language is : %d\t",temp1/n,temp2/n,temp3/n);
}
student *sort(student *head)
{student *head1,*p,*q,*r; int temp1=0,temp2=0,temp3=0,temp4; char s[15],n[15];
head1=head;
for(p=head1->next;p->next!=NULL;p=p->next)
{r=p;
for(q=p->next;q;q=q->next)
if(q->score.all>r->score.all)
r=q;
if(r!=p)
{strcpy(s,p->sid);strcpy(n,p->name);
temp1=p->score.english;
temp2=p->score.math;
temp3=p->score.c_language;
temp4=p->score.all;
strcpy(p->sid,r->sid);strcpy(p->name,r->name);
p->score.english=r->score.english;
p->score.math=r->score.math;
p->score.c_language=r->score.c_language;
p->score.