C语言程序设计教程第九章习题答案.docx
1、li 45 300.0chang 30 200.0chang2、#includestruct 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",student.name); 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",student.name); 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 0typedef 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)