《C语言程序设计的试题及答案.docx》由会员分享,可在线阅读,更多相关《C语言程序设计的试题及答案.docx(8页珍藏版)》请在第壹文秘上搜索。
1、charnum111;charname11;f1.oatscore(3;f1.oataverage;);intmain()structudjypesiu=“200601JWang二80.0,85.0.70叫:stu.avc11ge=rti=0jarca=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.udcintInain0stru
2、ctdataintm;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;:structstudentstru
3、ctstudentda(a2)=1.Mzhangsan60.70h(2.M1.isi89.90|);fdrti=0;i2:i+)datai.average=(data(i.score(0datai.score1.JV2.0;sun-average=sun-average+data(i.average:juim_average=sum_averageZ2:fbr(i=0;idatai).ave11gc)prin!f(*%5d%10s%5.2.datai.nun.da1.a(i.namc,da1.a(i.average);rc1.urn0:8.Minc1.udestructint_dataintd
4、1.,d2;);intmain()structint.datadata2=(2,3,5,6);inti;intsm=10;for(i=0i2i+)scanf(%d.datai.dI.dataiJ.d2);sum=datai.dIdatai.d2sum;printf(sum=%d)w3um);return0;输入:203040509.#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
5、. #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.ey,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. W
6、inc1.udeunionst(inta2:intb(2:intc;):intmain()unionsiy;y.a(0=10:y.c=30;return0:y.b1.1=20;printf(w%d,%dnwy.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.=u
7、ts.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(%dnpy);printf(%dn,(+p)-x);retmO:)19.ffinc1.udestructn(inix:charc:voidfundstructnb)b.x=20;b.c=,
8、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,20
9、10.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)print
10、f(所输入日期是该年第d天.);return0;)2.该程序完成的功能是从屏群上输入口期(年、月、日),计算其为该年的第几天。inc1.udestructdatejye(intyear:inimonth;in(day:):intmain()inidays=O.i:ininun.day112=(3128.31,3031.30,3131.30.31,30311:PrinIf(请输入日期(年月日)nw);scanty%d%d%dN,&date.ycan&date.inonth9&hte.n-dayi-1.+days:days=days+date.day:if(date,year%4=三=0Ada1.
11、e.year%100!=0|da1.e.yearn400=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+)d
12、ays=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()structCmPIOyxypccmp:PrintfV请输入职匚信息(职工号姓立月工资W):SCann,%s%s%.):print():return0;voidprint()IPrirnf(*职工号姓名月工资*w):primf(,%8s%8s%IO.2n-):)5.该程序完成从键盘输入10名学生信息(学号、姓名、成绩).用一个排序函数sort完成按学生成绩降序排列,并输出学生成绩排行卷。inc