新概念C语言能力教程练习试题10答案

新概念C语言能力教程练习试题10答案

ID:83426989

大小:1.30 MB

页数:15页

时间:2023-04-26

上传者:无敌小子
新概念C语言能力教程练习试题10答案_第1页
新概念C语言能力教程练习试题10答案_第2页
新概念C语言能力教程练习试题10答案_第3页
新概念C语言能力教程练习试题10答案_第4页
新概念C语言能力教程练习试题10答案_第5页
新概念C语言能力教程练习试题10答案_第6页
新概念C语言能力教程练习试题10答案_第7页
新概念C语言能力教程练习试题10答案_第8页
新概念C语言能力教程练习试题10答案_第9页
新概念C语言能力教程练习试题10答案_第10页
资源描述:

《新概念C语言能力教程练习试题10答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

10.1ᫀ᪀ᦪint,floatᵨᐵᓫᐗḄ᪀ᵨᡝḄᦪ஺᪀!"᦮!"ᐵᓫᐗḄ᪗%஺᪀ᵨ᪀!"஺10.2ᫀ᪀&ᡂᕒḄ)*ᐸ,᪀஺-./01ṹ#include#includestructdate(intyear,month,day;)5structstudent(intno;charnameflO];structdatebirthday;floatfm,fe;)5intmain()(structstudentstu1;stul.no=8;strcpy(stu1.name,“67')5stu1.fm=stu1.fe=90.0;stu1.birthday.day=1;stul.birthday.month=1;stu1.birthday.year=2012;printf(":;:=d

1"stul.no);printf(">?:=s

2"stu1.name);printf(n@A=dB%dᨴ%dA

3",stul.birthday.year,stul.birthday.month,stul.birthday.day);printf("ᦪ:ᡂD:=.1f

4n,stul.fin);printf("FGᡂD:=.1f

5",stul.fe);return0;)10.3ᫀ#include#includestructstudentintno;charname[10];floatfm,fe;H5

6intmain()structstudentstul,stu2;prinlf("IJᐭLM:@Ḅ:;>?ᦪ:NFGᡂD

7")5scanf("%d%s%f%f\&stul.no,&stu1.name,&stul.fm,&stu1.fe);scanf("%d%s%f%f\&stu2.no,&stu2.name,&stu2.fm,&stu2.fe);if(strcmp(stu1.name,stu2.name)<0)(printf(n:;=d>?=sᦪ:ᡂD:%.lfFGᡂD:=.lf

8*stul.no,stul.name,stuLfm,stul.fe);printf(H:;:%d>?=sᦪ:ᡂD:%.lfFGᡂD:=.11

9”,slu2.no,stu2.name,stu2.fm,stu2.fe);)else(printfC,:;=d>?=sᦪ:ᡂD:%,lfFGᡂD:=.1f

10u,stu2.no,stu2.name,stu2.fm,stu2.fe);printf(":;=d>?=sᦪ:ᡂD:%.lfFGᡂD:=.1f

11u,stu1.no,stul.name,stul.fm,stul.fe);)return0;)10.4ᫀ#includestructstudent(intno;charname[10];floatfm,fe;)5intmain()structstudentstu[5],temp;inti=0,j=0;printf(”IJᐭ5M:@Ḅ:;>?ᦪ:NFGᡂD

12“)5for(i=0;i<5;i++)scanf("%d%s%f%f\&stu[i].no,&stu[i].name,&stu[i].fm,&stu[i].fe);for(i=0;i<5;++i)for(j=i+l;j<5;++j)if(stu[i].fm>stu[j].fm)

13temp=stu[i];stu[i]=stu[j];stu[j]=temp;printf("ᢥ᯿ᦪ:ᡂDᓣ0᣸ᑡ:

14")5for(i=0;i<5;++i)printf(n:;=d>?=sᦪ:ᡂD=.IfFGᡂD:=.lf

15*stu[i].no,stu[i].name,stu[i].fm,stu[i].fe);return0;}10.5ᫀ᝞ᨵstructstudentstul,stu2;,WXYstul=stu2)Zᣚᡂ\ᦪ]ᵨassign(&stul,&stu2,sizeof(structstudent))o\ᦪassign᝞^஺voidassign(void*x,void*y,unsignedsize)(char*px,*py;px=(char*)x;py=(char*)y;if(px!=py)while(size—)*px++=*py++;)10.6ᫀ_`ᢣ┐!"*cdefgᵨᢣᔣḄ᪀ᓫᐗḄᡂᕒ!"Ygᵨᢣᔣᡂᕒijk->nop஺_`!"qdgᵨ᪀ᓫᐗḄᡂᕒ!"Ygᵨᡂᕒijk஺10.7ᫀ:r10-2&construct஺\ᦪsLMdoubletᦪ“vᔠ”ᡂM᪀Ḅxᦪ!"஺#includestructdate(intyear,month,day;);structdateconstruct(intyear,intmonth,intday)(structdatetemp;஻z{|}oᓫḄ~-if(year>0&&month>0&&month<=12&&day>0&&day<31)(temp.day=day;temp.month=month;temp.year=year;

16elsetemp.day=temp.month=temp.year=1;)returntemp;)intmain()(intyear,month,day;structdatedate1;printf("IJᐭBᨴA

17”)5scanf(n%d%d%dH,&year,&month,&day);date1=construct(year,month,day);printf("%dB=4ᨴ=4A

18",date1.year,date1.month,date1.day);return0;)10.8ᫀ஻\ᦪ&ᨵ⌕~-ᦪḄᔠឋ஺structdateaddDay(structdated)(structdated2;intflag=0;d2=d;++d2.day;switch(d2.month){case1:case3:case5:case7:case8:case10:case12:if(d2.day>31)(flag=1;break;)case2:if(d2.year%4==0&&d2.year%100!=0||d2.year%400==0)if(d2.day>29)

19flag=1;break;)elseif(d2.day>28)(flag=1;break;)default:if(d2.day>30)flag=1;)if(Rag==1)(d2.day=1;++d2.month;if(d2.month==13)(d2.month=1;++d2.year;))returnd2;)10.9ᫀ-./0᝞^#includestructstudent(intno;charnameflO];floatfm,fe;intmain()(structstudentstu1;printf("%d

20M,sizeof(stu1));return0;/0ḄJ

2124᪀&ᡂᕒᑖᓰ4Mஹ10Mஹ4Mஹ4M22⁚ᵫJ)▭ᓰ}24M⁚஺᪀!"ᡠᓰᓫᐗcNᨵYᔜᡂᕒ!"ᡠᓰᓫᐗN஺ᙠḕ^C¡¢ᘤ¤M!"ᡈᦪᓫᐗᢥᐸᯠ§¨ᩩªᑖ«c஺ᙠ᪀&¡¢ᘤ᪀Ḅ¤Mᡂᕒᢥᐸᯠ§¨(alignment)ᩩªᑖ«c஺ᔜMᡂᕒᢥ᯿,¬®¯Ḅ°0ᙠᑁ&°0(ᡂᕒc)²ᨵ³ᐭḄ⁚)´MᡂᕒḄᙢᙬN᦮M᪀Ḅᙢᙬ·஺C¡¢ᘤḕḄ᪀ᡂᕒᯠ§¨ᩩª“N⁚§¸”NᓽºᡂᕒᦪḄ»¼஺᝞intᡂᕒḄᯠ§¨ᩩª4⁚§¸½doubleḄ᪀ᡂᕒḄᯠ§¨ᩩª8⁚§¸஺¾ºᡂᕒḄ¿ÀÁÂúᡂᕒḄ“ÄÅᯠ§¨ᩩª”ᑣᙠÇM⁚☢É☢ÊË〉ÍMᦪḄ⁚஺C¡¢ᘤḕḄ᪀᦮ÎḄᯠ§¨ᩩªº᪀ᡠᨵᡂᕒ&⌕ÏḄᨬᜧᯠ§¨ᩩª஺¾᪀Îᔜᡂᕒ»¼N“᪀᦮Îᯠ§¨ᩩªḄ᦮ᦪÒᑣᙠᨬÉMᡂᕒÉÓᐙ⁚10.10ᫀ1ṹ᝞^#include#includestructstudent(intno;charnamef10];floatfm,fe;)5intstudentcmp(constvoid*pl,constvoid*p2)(return((structstudent*)pl)->fm-((structstudent*)p2)->fm;)intmain()(structstudentstu[5];inti=0,j=0;printf(”IJᐭ5M:@Ḅ:;>?ᦪ:NFGᡂD

22)for(i=0;i<5;++i)scanf("%d%s%f%f\&stu[i].no&stu[i].name,&stu[i].fm,&stu[i].fe);5qsort(stu,5,sizeof(structstudent),studentcmp);printf("ᢥ᯿ᦪ:ᡂDᓣ0᣸ᑡÉ:

23)for(i=0;i<5;++i)printf(n:;=d>?=sᦪ:ᡂD=.IfFGᡂD:=.1f

24n,stu[i].no,stu[i].name,stu[i].fm,stu[i].fe);return0;

2510.11ᫀ#include#includestructstudent(intno;charname[10];floatfm,fe;structstudent*next;)5intmain()(structstudent*phead,*ptemp,*stu;inti,n;phead=stu=NULL;printf(”IJᐭ:@Õᦪ:

26")5scanf("=d;&n);fbr(i=l;i<=n;++i)(ptemp=(structstudent*)malloc(sizeof(structstudent));if(ptemp==NULL)(printf("ᑁᑖ«ᜫ×!

27")5return1;)printf("IJᐭ´%dM:@ḄÙÚ:",i);scanf(u%d%s%f%f\&ptemp->no,ptemp->name,&ptemp->fm,&ptemp->fe);if(i==l)phead=stu=ptemp;else(stu->next=ptemp;stu=stu->next;))if(stu!=NULL஻■ÝM:@Þᨵstu->next=NULL;printf(H

28

29M);for(ptemp=phead;ptemp!=NULL;ptemp=ptemp->next)printf(n:;=d>?=sᦪ:ᡂD=.IfFGᡂ1f

30'\ptemp->no,ptemp->name,ptemp->fm,ptemp->fe);return0;

3110.12ᫀ#include#includestructstudent(intno;charname[10];floatfm,fe;structstudent*next;)5஻Ꮇàᜮâheadã⊤&´0Mâ஺intinsert(structstudent*phead,intn,structstudent*pnew)(inti=0;structstudent*pl,*p2;if(pnew==NULL)return2;for(pl=phead;pl!=NULL&&inext)++i5if(pl==NULL)return1;p2=pl->next;pl->next=pnew;pnew->next=p2;return0;)intmain()(structstudenthead,*ptail=&head,*ptemp;inti,n;printf(”IJᐭ:@Õᦪ:

32");scanf(n%d",&n);fbr(i=l;i<=n;++i){ptemp=(structstudent*)malloc(sizeof(structstudent));if(ptemp==NULL)(prinlf("ᑁᑖ«ᜫ×!

33")5return-1;)printf("IJᐭ´%dM:@ḄÙÚ:

34”,i);scanf(u%d%s%f%f,&ptemp->no,ptemp->name,&ptemp->fm,&ptemp->fe);ptail->next=ptemp;ptail=ptail->next;

35ptail->next=NULL;ptemp=(structstudent*)malloc(sizeof(structstudent));if(ptemp==NULL)(printæᑁᑖ«ᜫ×ᑖ)return-1;}printf(”IJᐭçË:@ḄÃè:

36");scanf("%d",&i);printf(”IJᐭçË:@ḄÙÚ:

37");scanf(n%d%s%f%f,&ptemp->no,ptemp->name,&ptemp->fm,&ptemp->fe);printf("%d

38'\insert(&head,i,ptemp));fbr(ptemp=head.next;ptemp!=NULL;ptemp=ptemp->next)printf(H:;:%d>?:%sᦪ:ᡂD%.IfFGᡂDptemp->no,ptemp->name,ptemp->fm,ptemp->fe);return0;)10.13ᫀintdel(structstudent*phead,intn)(inti=0;structstudent*pl,*p2;for(pl=phead;pl!=NULL&&i!=n-l;pl=pl->next)++i5if(pl==NULL||n<=0)return1;p2=pl->next;if(p2!=NULL)(pl->next=p2->next;deletep2;return0;)return2;)10.14ᫀ#include#includestructstudent(intno;charname[10];

39floatfm,fe;structstudent*next;)5intmain()(structstudenthead,*ptail=&head,*ptemp;inti,n;printf(”IJᐭ:@Õᦪ:

40”)5scanf(n%d",&n);fbr(i=l;i<=n;++i)(ptemp=(structstudent*)malloc(sizeof(structstudent));if(ptemp==NULL)(printf("ᑁᑖ«ᜫ×!

41")5return-1;)printf("IJᐭ´%dM:@ḄÙÚ@”,i);scanf(n%d%s%f%f\&ptemp->no,ptemp->name,&ptemp->fm,&ptemp->fe);ptail->next=ptemp;ptail=ptail->next;)ptail->next=NULL;fbr(ptemp=head.next;ptemp!=NULL;ptemp=ptemp->next)printf(n:;:%d>?:%sᦪ:ᡂD=.IfFGᡂDptemp->no,ptemp->name,ptemp->fm,ptemp->fe);ptail=head.next;ptemp=ptail->next;ptail->next=NULL;while(ptemp!=NULL)(head.next=ptemp;ptemp=ptemp->next;head.next->next=ptail;ptail=head.next;)printf("ZèÉḄã⊤:

42)fbr(ptemp=head.next;ptemp!=NULL;ptemp=ptemp->next)printf(":;:%d>?:%sᦪ:ᡂD=.IfFGᡂD%.lf

43",ptemp->no,ptemp->name,ptemp->fm,ptemp->fe);return0;10.15ᫀ:

44#include#includestructstudent(intno;charname[10];floatfm,fe;structstudent*next;)5intmain()(structstudenthead,*ptail=&head,*ptemp,*pl,*p2;inti,n;printf(”IJᐭ:@Õᦪ:

45");scanf("=d”,&n);fbr(i=l;i<=n;++i){ptemp=(structstudent*)malloc(sizeof(structstudent));if(ptemp==NULL)(printf("ᑁᑖ«ᜫ×ᑁ)return-1;)printf("IJᐭ´%dM:@ḄÙÚ:

46”,i);scanf(u%d%s%f%f,&ptemp->no,ptemp->name,&ptemp->fm,&ptemp->fe);ptail->next=ptemp;ptail=ptail->next;)ptail->next=NULL;fbr(ptemp=head.next;ptemp!=NULL;ptemp=ptemp->next)printf(H:;:%d>?:%sᦪ:ᡂD%.IfFGᡂDptemp->no,ptemp->name,ptemp->fm,ptemp->fe);ptail=head.next->next;head.next->next=NULL;while(ptail!=NULL)(pl=ptail;ptail=ptail->next;for(p2=&head;p2->next!=NULL&&(p2->next)->fmfm;p2=p2->next)if(p2->next==NULL)

47pl->next=NULL;p2->next=pl;)else(pl->next=p2->next;p2->next=pl;)}printf("ᢥᦪ:ᡂD᣸0ÉḄ:@ÙÚ᝞^:

48")for(ptemp=head.next;ptemp!=NULL;ptemp=ptemp->next)printf(M:;:%d>?:%sᦪ:ᡂD%.IfFGᡂD%.lf

49n,ptemp->no,ptemp->name,ptemp->fm,ptemp->fe);return0;110.16ᫀ\ᦪconstruct(intn)r10-4&construct\ᦪḄêëf,_`\ᦪḄìíXî}ïðã⊤ḄMâḄᙢᙬ஺10.17ᫀ:\ᦪplay·᪵òó}r104&Ḅôᦪ`/஺10.18ᫀ#include#includestructnode(doubledata;structnode*next;)5intmain()(inti;structnode*head,*p,*q;head=(structnode*)malloc(sizeof(structnode));if(head!=NULL)scanf(u%lf',&head->data);p=head;for(i=l;i<10;++i)(q=(structnode*)malloc(sizeof(structnode));if(q==NULL)return1;scanf(,'%lf,,&q->data);p->next=q;

50p=p->next;p->next=head;for(p=head;p->next!=head;p=p->next)printf(M%fp->data);printf(',%f

51",p->data);)10.19ᫀ#include#include#defineN10structnode(doubledata;structnode*next;)5intmain()(inti;doublesum=0,min;structnode*head,*p,*q;printf("IJᐭ=dMtᦪ!

52”,N);head=(structnode*)malloc(sizeof(structnode));if(head!=NULL)scanf("%lf,&head->data);p=head;for(i=l;idata);p->next=q;p=p->next;)p->next=head;p=head;q=p5for(i=0;i<3;++i)(sum+=q->data;q=q->next;min=sum;

53printf(M%.lf°,sum);for(p=p->next;p->next!=head;p=p->next)(q=p5sum=0;for(i=0;i<3;++i)(sum+=q->data;q=q->next;)printf(n%.lfn,sum);if(sumdata;p=p->next;)printf("%.lf°,sum);if(sum

54Min:%f

55n,min);)10.20ᫀ:/0õÀY᪗%kINTA»¼3Ḅö᦮ᦪvḄḄ?▭jᵨ÷ᢣ᪗%kḄjᵨ÷INTAᙠ/0&øᜐõÀqᑮ/0ûᜐÝ¿jᵨᓽ⍗ᑮY⊤ý?஺/0&xᔠGþÿ☢INTAḄ᦮ᐕᵨḄ᪗஺ᵨᯠḄ᪗ᨵᦔ஺!"#$%&123910.21(ᫀ&ὶᔠᡂᕒḄ./0#᪀234567%2Ḅὶᔠᦪ9ᐜ;ᵨ5<ᦪ9ᐗ>4Ḅ#᪀ᡂᕒᯠ;ᵨ5ᐸ4ᐗ>Ḅ᦮ᡂᕒ஺23Ḅ!"#$%&11,1221,222310.22(ᫀ&ὶᔠ@ᒹB5Cᡂᕒᦑ/0E᪀⌼.GH#᪀ḄIᜐᙠLMNᡂᕒᐳPQRᓫᐗTUὶᔠVWᓄYᯠ@◤ᵨ[\]Gᐸ4^_ᨵV`஺a2bcdṹ᝞g&#include

56unionTestinti;floatf;};voidmain()(unionTestu={3};printf("%d

57M,u.i);(hi#$&310.23(ᫀjkᵨᡝm.ᑡk"U.ᦪoᡠᨵ/_Ḅq`r/0ᵨsjkjkḄq`t▲Ljkᑡk"Ḅ`஺jkḄ;ᵨ/0᩽ᜧᙢyz23Ḅ/{ឋ஺23}ᜧ23Ḅ/{ឋ}⌕஺

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
最近更新
更多
大家都在看
近期热门
关闭