C语言 课后题答案9

上传人:tang****xu1 文档编号:132720961 上传时间:2020-05-19 格式:DOC 页数:14 大小:145.50KB
返回 下载 相关 举报
C语言 课后题答案9_第1页
第1页 / 共14页
C语言 课后题答案9_第2页
第2页 / 共14页
C语言 课后题答案9_第3页
第3页 / 共14页
C语言 课后题答案9_第4页
第4页 / 共14页
C语言 课后题答案9_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《C语言 课后题答案9》由会员分享,可在线阅读,更多相关《C语言 课后题答案9(14页珍藏版)》请在金锄头文库上搜索。

1、1、li 45 300.0chang 30 200.0chang2、#includestruct students char sid100; char name100; float score3;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(

2、%f,%f,%f,&student.score0,&student.score1,&student.score2); printf(nsid = %s,student.sid); printf(nname = %s,student.name); j=(student.score0+student.score1+student.score2)/3.0; printf(naverage = %.2f,j); getch();3、#include#include#define F sizeof(student)#define NULL 0typedef struct scoresint englis

3、h;int math;int c_language;int all;TP;typedef struct studentschar sid15;char name15;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(nnPlease input %d student message: nn,n); printf(t%d studen

4、t sid: ,n); p1=(student *)malloc(F);p1-next=NULL; scanf(%s,p1-sid); printf(nt%d student name: ,n); scanf(%s,p1-name); printf(nt%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.

5、c_language; if(n=1) head-next=p1;p2=p1; else p2-next=p1;p2=p1; printf(nntttContinue 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(nnname: %staverage: %d,p-name,j);p=p-next; printf(n

6、nnPress 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(nnaverage english is : %dnaverage math is : %dnaverage c_language is : %dt,temp1/n,temp2

7、/n,temp3/n);student *sort(student *head)student *head1,*p,*q,*r; int temp1=0,temp2=0,temp3=0,temp4; char s15,n15;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.allr-score.all) r=q;if(r!=p)strcpy(s,p-sid);strcpy(n,p-name);temp1=p-score.english;temp2=p-score.m

8、ath;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.all=r-score.all;strcpy(r-sid,s);strcpy(r-name,n);r-score.english=temp1;r-score.math=temp2;r-score.c_languag

9、e=temp3;r-score.all=temp4;return head1;void output(student *head)student *head2,*p;int i=1;clrscr();head2=sort(head);for(p=head2-next;p!=NULL;p=p-next) printf(nnname: %stsid: %stenglish: %dtmath: %dtc_language: %dtaverage: %dtmingci: %d,p-name,p-sid,p-score.english,p-score.math,p-score.c_language,p-

10、score.all/3,i+);average2(head); printf(nnnttPress eny key back.);getch();void main()student *head,*p1,*p2;int i=0,j=1;head=input();do clrscr();printf(nn(1): average1.nn(2): average2.nn(3): sort.nn(4): output.nnn Please choose: );scanf(%d,&i);switch(i)case 1: average1(head); break;case 2: clrscr();av

11、erage2(head); printf(nnnPress eny key retuen.);getch(); break;case 3: clrscr();p1=sort(head);for(p2=p1-next;p2!=NULL;p2=p2-next) printf(nttname: %stmingci:%d,p2-name,j+);printf(nnnPress eny key back.);getch(); break;case 4: output(head); break;default: printf(nYour choose is not right.);break;while(

12、i!=-1);4、#include#include#define NULL 0#define F sizeof(worker)typedef struct workchar sid15;char name15;int money;struct work *next;worker;int min=0,max=0;char a15,b15;worker *input()worker *head,*p,*q;int n=0;char ch;head=(worker *)malloc(F); head-next=0;don+;p=(worker *)malloc(F); p-next=0;printf(nntPlease input %d worker message : ,n);printf(n%d worker sid: ,n);scanf(%s,p-sid);printf(n%d worker name: ,n);scanf(%s,p-name);printf(n%d worker money: ,n);scanf(%d,&p-money); if(n=1) head-next=p; q=p; max=p-money;strcpy(a,p-name); min=p-money;strcpy(b,p-name);else q-next=p;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 商业计划书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号