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

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、1、li45300.0200.0chang 30chang2、#include<stdio.h>struct students char sid100; char name100; float score3; student; void main() int i; float j;Please input sid: );scanf(%s,student.sid);Please input name:);scanf(%s,);Please input 3 score:(like1,1,1)輸入逗號隔開 */scanf(%f,%f,%f,&student

2、.score0,&student.score1,&student.score2);sid = %s,student.sid);name = %s,);j=(student.score0+student.score1+student.score2)/3.0;average = %.2f,j);getch();、3#include<stdio.h>#include<string.h>#define Fsizeof(student)#define NULL 0typedef struct scoresint english; intma

3、th;int c_language;int all;TP;typedef struct studentschar sid15; charname15; TPscore;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+;nPlease input %d student message:nn,n);%dstudent sid:p1=(student *)ma

4、lloc(F);p1->next=NULL;scanf(%s,p1 ->sid);t%d student name:scanf(%s,p1 ->name);t%d student scores(englesh,math,c_language):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_l

5、anguage; if(n=1) head ->next=p1;p2=p1; elsep2->next=p1;p2=p1;ntttContinue or back (press y/n):);ch=getch();while(ch='y'|ch='Y');return head;void average1(student *head)int j;student *p;clrscr();p=head ->next;while(p) j=p ->score.all/3;nname: %staverage: %d,p->name,j);

6、p=p ->next;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+;naverage english is : %dnaverage math is : %dnaverage

7、 c_languageis : %dt,temp1/n,temp2/n,temp3/n); student *sort(student *head)student *head1,*p,*q,*r; inttemp1=0,temp2=0,temp3=0,temp4; char s15,n15;head1=head;for(p=head1 ->next;p ->next!=NULL;p=p->next)for(q=p ->next;q;q=q ->next)r=p;if(q ->score.all>r ->score.all)r=q;if(r!=p)

8、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_l

9、anguage=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; return head1; void output(student *head) student *head2,*p;int i=1;clrscr();head2=sort

10、(head);for(p=head2 ->next;p!=NULL;p=p->next)taverage: %dtmingci: %d,p->name,p ->sid,p ->score.english,p ->score.math,p ->score.c_language,p ->score.all/3,i+);average2(head);nnttPress eny key back.);getch();void main()student *head,*p1,*p2; inti=0,j=1; head=input();doclrscr();

11、sort.nn(4):output.nnnn(1):Please choose:);scanf(%d,&i);switch(i)break;case 1: average1(head);nnPressenykeycase 2:clrscr();average2(head); retuen.);getch(); break; case 3: clrscr();p1=sort(head);for(p2=p1 ->next;p2!=NULL;p2=p2->next)ttname: %stmingci:%d,p2-nnPress eny key back.);getch(); br

12、eak;case 4: output(head); break;Your choose is not right.);break;while(i!= -1);4、#include<stdio.h>#include<string.h>#define NULL 0#define F sizeof(worker)typedef struct workchar sid15; charname15; intmoney; structwork *next;worker;int min=0,max=0;char a15,b15;worker *input()worker *head,

13、*p,*q;int n=0;char ch;head=(worker *)malloc(F); head->next=0;don+;p=(worker *)malloc(F); p->next=0;ntPlease input %d worker message : ,n);%d worker sid: ,n);scanf(%s,p-%dworker name: ,n);scanf(%s,p-%d workermoney: ,n);scanf(%d,&p->money); if(n=1)head ->next=p; q=p; max=p ->money;s

14、trcpy(a,p ->name); min=p ->money;strcpy(b,p ->name); elseq ->next=p;if(p ->money>max)max=p ->money;strcpy(a,p ->name); if(p ->money<min) min=p ->money;strcpy(b,p ->name); q=p;tty/n);ch=getch();while(ch='y'|ch='Y');return head;void output()clrscr();

15、The max money is:The min money is:void main()input();output();getch();、 6、5椣據(jù)畬敤獜摴?jié)潠?define F sizeof(stu)#define NULL 0typedef struct 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+;nn,n);nPlease inp

16、ut %d student message:%d student sid:p1=(stu*)malloc(F);p1 ->next=NULL;scanf(%d,&p1 ->sid);t%d student average:scanf(%d,&p1 ->average);if(n=1) head ->next=p1;p2=p1; elsep2->next=p1;p2=p1;ntttContinue or back (press y/n):);ch=getch();while(ch='y'|ch='Y');return

17、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;clrscr();p=head ->next;r=(stu *)malloc(sizeof(stu);r->sid=x;r->average=y;如果插入空表if(p=NULL)/*/ p=r;r->next=NULL;insert success!); else

18、while(x>p ->sid) 找到插入的位置,按學號大小。/* (找到位置或者到了表尾都*/會跳出循環(huán))if(p ->next=NULL)break; p=p->next; 插到中間位置if(x<p ->sid)/* */r->sid=p ->sid; r ->average=p ->average;p->sid=x;p->average=y;r->next=p ->next;p->next=r;insert success!);學號不能相同else if(x=p ->sid)/* */Erro

19、r ->your input this same sid.);*/插到末尾 else/*p->next=r;r->next=NULL;insert success!); return head;的結點的指針得到位置為n stu *get(stu *head,int n) /*/stu *p;int i;p=head ->next;return head;if(n=0)elsefor(i=1;i<n;i+)p=p ->next;return p;stu *delete(stu *head,int sid)stu *p,*q;int temp=0,i=0;p=h

20、ead ->next;if(!p)list is empty.*/ 表空else*/while(p)查找學號為/*的結點的指針sidi+;*/sid標記學號為/*的結點的位置if(p->sid=sid)*/temp=1;break; /*temp=1標記找到了p=p ->next;if(temp=1) /*如果有學號為sid 的結點*/*/的前一個結點的指針得到sid q=get(head,i -1);/* q->next=p ->next;free(p);ndelete sucess !);return head; else/* 沒有找到 */nNO this

21、data.n);return head; void print(stu *head)stu *p;p=head ->next;list is empty.press eny key back.);getch();while(p)%d :t%d ,p ->sid,p ->average);p=p ->next; main()stu *p1,*p2;int n,i=0,j=0;do clrscr();char ch1;head=create();1. insert. );2. select.);3. delect.);4. print list. );5. EXIT );.

22、choice (1 -ch1=getch();switch(ch1)case '1': clrscr();please input insert sid. and average(like 1,1):);scanf(%d,%d,&i,&j);head=insert(head,i,j);nnPress eny key back.);getch();break;case '2': clrscr();input you want to selete sid: );scanf(%d,&n);p1=select(head,n);if(p1)sid:

23、%dtaverage:%d,p1->sid,p1 ->average);No this data.);elsennPress eny key back.);getch();break;'3':casePlease input you want delete sid:);scanf(%d,&n);head=delete(head,n);nnPress eny key back.);getch();break; case '4': clrscr();printf(All information :);print(head);nnPress eny key back.);getch();break;case '5': return;press eny keynYour enter is not right.while(n);、7 #include<stdio.h>#define F sizeof(L)typedef struct listchar data; struct list*next;L;L *set_list()L *head,*p1,*p2;char c;int n=0;*/head=(L *)malloc(F); head ->next=0;

溫馨提示

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

評論

0/150

提交評論