程序设计c语言教程杨路明6,C语言程序设计教程 杨路明 答案第9章

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值