C語言課后題答案(北郵出版社)_第1頁
C語言課后題答案(北郵出版社)_第2頁
C語言課后題答案(北郵出版社)_第3頁
C語言課后題答案(北郵出版社)_第4頁
C語言課后題答案(北郵出版社)_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、,.1、li45300.0chang 30200.0chang2、#includestruct studentschar 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,);printf(nplease input 3 score:(like1,1,1);/* 輸入逗號(hào)隔開*/scanf(%f,%f,%f,&stud

2、ent.score0,&student.score1,&student.score2);printf(nsid = %s,student.sid);printf(nname = %s,);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 english; int math;int c_l

3、anguage;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;don+;printf(nnplease input %d student message:nn,n);printf(t%d student sid:,n);p1=(stu

4、dent *)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.c_language; if(n=1) head-n

5、ext=p1;p2=p1; elsep2-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(nnnpress eny key return.);getch();

6、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(nnaverageenglishis:%dnaveragemathis:%dnaveragec_languageis : %dt,temp1/n,temp2/n,temp3/n);student *sort(student *head)

7、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.math; temp3=p-score.c_language; temp4

8、=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_language=temp3;r-score.all=temp4;

9、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-score.all/3,i+);average2

10、(head);.,.printf(nnnttpress eny key back.);getch();void main()student *head,*p1,*p2; int i=0,j=1; head=input();doclrscr();printf(nn(1):average1.nn(2):average2.nn(3):sort.nn(4):output.nnnplease choose:);scanf(%d,&i);switch(i)case 1: average1(head);break;case 2: clrscr();average2(head);printf(nnnpress

11、eny keyretuen.);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(nnnpresseny keyback.);getch();break;case 4: output(head);break;default: printf(nyour choose is not right.);break;while(i!=-1);4、#include#include#define null

12、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 mes

13、sage :,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);elseq-next=p;if(p-moneymax) max=p-money;strcpy(a,p-name); if(p-moneymoney;

14、strcpy(b,p-name); q=p;printf(ntty/n);ch=getch();while(ch=y|ch=y);return head;void output()clrscr();printf(nthe max money is:%dttname is: %snn,max,a);printf(nthe min money is:%dttname is: %s,min,b);void main()input();output();getch();5、 6、#includestdio.h#define f sizeof(stu)#define null 0typedef stru

15、ct studentint sid;int average;struct student *next;stu;stu *head;stu *create()stu *p1,*p2;int n=0;char ch;head=(stu *)malloc(f);head-next=null;.,.don+;printf(nnplease input %d student message:nn,n);printf(t%d student sid:,n);p1=(stu *)malloc(f);p1-next=null;scanf(%d,&p1-sid);printf(nt%d student aver

16、age:,n);scanf(%d,&p1-average);if(n=1) head-next=p1;p2=p1; elsep2-next=p1;p2=p1;printf(nntttcontinue or back (press y/n):);ch=getch();while(ch=y|ch=y);return head;stu *select(stu *head,int x)stu *s;s=head-next;while(s)if(s-sid=x)break;s=s-next;return s;stu *insert(stu *head,int x,int y)stu *p,*r,*q;c

17、lrscr();p=head-next;r=(stu *)malloc(sizeof(stu);r-sid=x;r-average=y;if(p=null)/*如果插入空表*/p=r;r-next=null;.,.printf(ninsert success!);elsewhile(xp-sid)/* 找到插入的位置,按學(xué)號(hào)大小。(找到位置或者到了表尾都會(huì)跳出循環(huán)) */if(p-next=null)break; p=p-next;if(xsid)/* 插到中間位置*/r-sid=p-sid; r-average=p-average;p-sid=x;p-average=y;r-next=p-n

18、ext;p-next=r;printf(ninsert success!);else if(x=p-sid)/* 學(xué)號(hào)不能相同*/printf(nerror-your input this same sid.);else/* 插到末尾 */p-next=r;r-next=null;printf(ninsert success!);return head;stu *get(stu *head,int n)/* 得到位置為n 的結(jié)點(diǎn)的指針*/stu *p;int i;p=head-next;if(n=0)return head;elsefor(i=1;inext; return p;stu *de

19、lete(stu *head,int sid)stu *p,*q;int temp=0,i=0;p=head-next;if(!p)printf(nlist is empty.press eny key back.);getch();return head;/* 表空 */elsewhile(p)/* 查找學(xué)號(hào)為sid 的結(jié)點(diǎn)的指針*/i+;/*標(biāo)記學(xué)號(hào)為sid 的結(jié)點(diǎn)的位置 */;.,.if(p-sid=sid)temp=1;break; /*temp=1標(biāo)記找到了 */p=p-next;if(temp=1) /* 如果有學(xué)號(hào)為sid 的結(jié)點(diǎn) */q=get(head,i-1);/* 得到

20、sid 的前一個(gè)結(jié)點(diǎn)的指針*/q-next=p-next;free(p);printf(nndelete sucess !);return head;else/* 沒有找到 */printf(nnno this data.n); return head;void print(stu *head)stu *p;p=head-next;if(!p)printf(nlist is empty.press eny key back.);getch();while(p)printf(n%d :t%d ,p-sid,p-average);p=p-next;main()stu *p1,*p2;char ch

21、1;int n,i=0,j=0;head=create();doclrscr();printf(n1. insert.);printf(n2. select.);printf(n3. delect.);printf(n4. print list.);printf(n5. exit);printf(n.choice (1-5).);ch1=getch();switch(ch1);.,.case 1: clrscr();printf(nplease input insert sid. and average(like 1,1):);scanf(%d,%d,&i,&j);head=insert(he

22、ad,i,j);printf(nnnpress eny key back.);getch();break;case 2: clrscr();printf(ninput you want to selete sid:);scanf(%d,&n);p1=select(head,n);if(p1) printf(nsid:%dtaverage:%d,p1-sid,p1-average);elseprintf(nno this data.);printf(nnnpress eny key back.);getch();break;case3:clrscr();printf(nplease input

23、you want delete sid:);scanf(%d,&n);head=delete(head,n);printf(nnnpress eny key back.);getch();break;case4: clrscr();printf(all information :);print(head);printf(nnnpress eny key back.);getch();break;case 5: return;default: printf(nnyour enter is not right.press eny key back.);getch();while(n);7、#include#define f sizeof(l)typedef struct list;.,.char data; struct list *next;l;l *set_list()l *head,

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論