C语言程序设计的试题及答案.docx
charnum111;charname11;f1.oatscore(3;f1.oataverage;);intmain()structudjypesiu=“200601"JWang二80.0,85.0.70叫:stu.avc11ge=<s1.u.scoreO)+s1.u.sc0re1+s1.u.scorv2)3;prin1.fCaverage=%5.2Cn".s1.u.average);return0;3.Minc1.udeunionout(inta(2:struct(intb;intc;in:intd:):intnain()(unionoutc;inti;c.in.b=1;c.in.c=2;printf(M%5dM,c.a(i|);Printfreturn0;e.d=3;ft>rti=0j<2zi+)4.Winc1.ude#dcfincPI3.14structCij1.ype(f1.oatr:doub1.earea:intnain()structCiJIyPecir=(5.0).*p=&cir:p->arca=PPp->rp->11p11ntf(,arca=%.3n".p->arva);return0;5.#inc1.udcstructint_char(inti;charch;);intmain()structint_charx=9,N;printf(*'t%5cn,x.i+20,x.ch-2);return0;6.#inc1.udcintInain0structdataintm;intn;union(inty;imz;da;structdataintdata;intdata.m=3;intdata.n=6;in(da(a.da.y=intda(a.n+inidata.n;i11da(a.da.z=intda(a.m-intdata.n;pri11tf(*%5d%5dn,intdata.da.yjntda1.a.da.z):return0:7.Winu1.udeintnain()(inti:oatsun-average=0;(intnum:charnanc(10;intscorc(2:f1.oataverage;:structstudentstructstudentda(a2)=1.Mzhangsan60.70h(2.M1.isi89.90|);fdrti=0;i<2:i+)datai.average=(data(i.score(0÷datai.score1.JV2.0;sun-average=sun-average+data(i.average:juim_average=sum_averageZ2:fbr(i=0;i<2:i+)if(sum_average>datai).ave11gc)prin!f(*%5d%10s%5.2.datai.nun.da1.a(i.namc,da1.a(i.average);rc1.urn0:8.Minc1.udestructint_dataintd1.,d2;);intmain()structint.datadata2=(2,3,5,6);inti;intsm=10;for(i=0i<2i+÷)scanf("%d''.datai.dI.dataiJ.d2);sum=datai.dI÷datai.d2÷sum;printf("sum=%d)w3um);return0;输入:20304050<回车>9.#iw1.udein(main()unionexastruct(inta;intb;out;intc;intd;e;c.out.a=10;c.out.b);return0;e.out,b=20;e.c=2:c.d=5;Primfr%d,%d11,c.out.a,10. #inc1.udcstructstinta;intb;unionintc;intf;)c;intmain()(structsty;y.a=10;y,c,e=20;y.c.f=y.a;y,b=y.c.e;printf(M%d,%dn*y.c.e»y,c.f);return0;)11.#inc1.udestructsia(inta:charb;):structstb(inta:charb:structMac:;i11(nain()strc(stby;y.a=i:y.b='X':y.c.a=y.a5*2:y.c.b=y.b-:Prin1.fr%d.%cW.y.CayCb):return0;)12. Winc1.udeunionst(inta2:intb(2:intc;):intmain()unionsiy;y.a(0=10:y.c=30;return0:y.b1.1=20;printf(w%d,%dnw>y.a(O,y.a(1);13. ffinc1.udestruct1.wo(intn;charch;:voidmain()struct(woexI三(5,V);rintR"%d,%cn*exI.n+I0.ex1.ch-1):J14. Winc1.udestructIwo(intn;charch:;voidfunc(s1.ructIWoeX2);voidmain()structtwoex1.=<6.*v');func(cxI);p11nf("%d,%cn*,cxI.n,cxI.ch);gctchar();voidfunc(structtwocx2)cx2.n=cx2.n+20;cx2.ch=cx2.ch-I;15.#inc1.udcunioncxastruct!inta;intb;Jout;intc;intd;voidnuin()unionexae;e.c=ke,d=3;e.ot,a=e.c;e,ouc.b=e.d;rintfC%d.%dn".e.out.a.e.oui.b):16.inc1.udestructSIU(in(a;intb;srucoi(intx;inty;Iins;):voidnain()(structstuouts;outs.a=1.1;outs.b=4;outs.ins.x=ou1.s.a÷outs.b:ou1.s.ins.y=ou1.s.a-ou1.s.b:prin1.ft*,id,*4d",>uts.ins.x.ou1.s.ins.y):17.#inc1.udcstructabcinta,b,c;);intmain()structabes2=123,4J,6;intt;t=s(0.as1J.c;printf(wt=%dn,);returnO;18.inc1.udestructst(intx.y;Jdaia(2=1.10.2.20);intmain()structStttP=data;Prin1.f("%dn"p>y);printf("%dn,(÷+p)->x);retmO:)19.ffinc1.udestructn(inix:charc:voidfundstructnb)b.x=20;b.c=,y,:)intmain()structna=1().,x*;func(八);Prin1.f("%d.%c”.a.x,a.c);returnO:)20. inc1.udeintnain()(structEXAMP1.Estructintx:inty;in:inia:intb:Je:e.a=1;c.b=2;c.in.x=c.a*c.b;c,in.y=c.a+c.b;Prifnf1.("%d”,c.in.x,c.in.y);return0;解答:1.162.A2.average=78,333.324.area=78,55.296.7.-33x1Zhangsan65.008. sum=1509. 5,2010.IOJO11.20.X12.30,2013.1514.6.v15.3.316.15.717.t=718.10219.0.x20.2.3三.补充程序1.该程序完成的功能是从屏窑上输入日期(年、月、H),计算其为该年的第几天。/inc1.udestruc(daieiype(iniyear:intmonth:iniday:inimain()intdays=0j;structdatejvpedate:intnon.day112J=(31.28.31,3031,0.313130.31J0.31);Prin1.fr清输入日期(年月日An)scanfCt%d%d%d,');fr(i=IJ=3)printf("所输入日期是该年第d天.);return0;)2.该程序完成的功能是从屏群上输入口期(年、月、日),计算其为该年的第几天。inc1.udestructdatejye(intyear:inimonth;in(day:):intmain()inidays=O.i:ininu>n.day112=(3128.31,3031.30,3131.30.31,30311:PrinIf("请输入日期(年月日)nw);scanty"%d%d%dN,&date.ycan&date.inonth9&<hte.<1.ay);for(i=1;:i+)days=11M>n-dayi-1.+days:days=days+date.day:if(date,year%4=三=0Ada1.e.year%100!=0|da1.e.year"n400=0)&&)days=days+1.;printf(所输入H期是该年第d天W.);return0;3.该加了完成的功能是从群幕卜.输入日期(年、小Ib.计比其为该年的笫儿&inc1.udestructdate_type(intyear:intmonth;intday;):intmain()inidays=0.i;structdate-typedate:intmon.day112J=131,283130,31.30.31,31303130.31):Prin1.fc右输入日期(月日)A):scanf(H%d%d%d",);for(i=I;u+÷)days=moo_dayi1+days;days=days+dae.day:if(date.ye4iro4=0&&da1.e.year%I(X)!=O)&&date.inon1.h>=3)days=days+1;printf(w所输入日期是该年第d大,);return0;)4.该程序实现从键盘输入1名职工的信息:职工号、姓名、月工资,由prim函数完成这名职工信息的输出,inc1.udestructCmP1.oycJIyPecharnun20;charnane20;oapay:;voidPrint(StnIC1.emp1.oyeeJypeenp1.):in(nain()structCmPIOy<xypccmp:PrintfV请输入职匚信息(职工号姓立月工资W):SCann,%s%s%.):print():return0;voidprint()IPrirnf("*职工号姓名月工资*w):primf(',%8s%8s%IO.2n-):)5.该程序完成从键盘输入10名学生信息(学号、姓名、成绩).用一个排序函数sort完成按学生成绩降序排列,并输出学生成绩排行卷。inc