C语言程序设计教程_李含光_郑关胜_清华大学习题答案习题答案[完美打印版]

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1第1章习题参考答案1.单项选择题(1)A(2)C(3)D(4)C(5)B2.填空题(1)函数(2)主函数(main)(3)printf(),scanf()第2章习题参考答案1.单项选择题1-5CBCCC6-10CDCDC11-13DBB2.填空题(1)1(2)26(3)6,4,2(4)10,6(5)3.000000(6)双精度(double)(7)9(8)字母,数字,下划线(9)13.700000(10)11(11)((m/10)%10)*100+(m/100)*10+m%10(12)0(13)10,9,11(15)(x0&&y0)||(x0&&z0)||(y0||z0)(16)double(17)x==0(18)sqrt(fabs(a-b))/(3*(a+b))(19)sqrt((x*x+y*y)/(a+b))第3章习题参考答案1.单项选择题1-5CCCDD6-10BCDBC11-15BCBBB16A2.填空题(1)用;表示结束(2){}(3)y=x0?1:x==0?0:-1(4)y%4==0&&y%100!=0||y%400==0(5)上面未配对(6)default标号(7)while,dowhile,for(8)dowhile(9)本次(10)本层3.阅读程序,指出结果(1)yes(2)*&(3)ABother(4)2870(5)2,0(6)8(7)36(8)1(9)3,1,-1,3,1,-1(10)a=12,y=12(11)i=6,k=4(12)1,-24.程序填空(1)x:y,u:z(2)m=n,m!=0,m=m/10(3)teps,t*n/(2*n+1),printf(“%lf\n”,2*s)(4)m%5==0,printf(“%d\n”,k)(5)cx=getchar(),cx!=front,cx2(6)doubles=0,1.0/k,%lf(7)s=0,sgmin,5.编程题(1).#includestdio.hintmain(){doublex,y;scanf(%lf,&x);if(x1)y=x;elseif(x=1.0&&x10)y=2*x-11;elsey=3*x-11;printf(%lf\n,y);return0;}(2).#includestdio.hintmain(){doublex,y,z,min;scanf(%lf%lf%lf,&x,&y,&z);if(xy)min=y;elsemin=x;if(minz)min=z;printf(min=%lf\n,min);return0;}(3).#includestdio.hintmain(){inty,m,d,flag,s=0,w,i;scanf(%d%d%d,&y,&m,&d);flag=(y%4==0&&y%100!=0||y%400==0);w=((y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400)%7;for(i=1;i=m;i++){switch(i){case1:s=d;break;case2:s=31+d;break;case3:s=59+d;break;case4:s=90+d;break;case5:s=120+d;break;case6:s=151+d;break;case7:s=181+d;break;case8:s=212+d;break;case9:s=243+d;break;case10:s=273+d;break;case11:s=304+d;break;case12:s=334+d;break;}}if(flag==1&&m2)s=s+1;s=(w+s)%7;if(s==0)printf(星期日\n);elseprintf(星期%d\n,s);return0;}3(4).#includestdio.hintmain(){floatp,r;scanf(%f,&p);if(p=10)r=p*0.1;elseif(p10&&p=20)r=10*0.1+(p-10)*0.075;elseif(p20&&p=40)r=10*0.1+10*0.075+(p-20)*0.05;elseif(p40&&p=60)r=10*0.1+10*0.075+20*0.05+(p-40)*0.03;elseif(p60&&p=100)r=10*0.1+10*0.075+20*0.05+20*0.03+(p-60)*0.015;elseif(p100)r=10*0.1+10*0.075+20*0.05+20*0.03+40*0.015+(p-100)*0.01;printf(%f\n,r);return0;}(5).#includestdio.hintmain(){charc;while((c=getchar())!='\n'){if(c='a'&&c='z')c=c-32;putchar(c);}return0;}(6).#includestdio.hintmain(){intm,k=2;printf(输入一个正整数:\n);scanf(%d,&m);while(km)if(m%k==0){printf(%4d,k);m=m/k;}elsek++;printf(%4d\n,m);return0;}(7).#includestdio.hintmain(){inta,n,s=0,p=0,i;scanf(%d%d,&n,&a);for(i=1;i=n;i++){p=p*10+a;s=s+p;}printf(%d\n,s);return0;}(8).#includestdio.hintmain()4{inti,j,k;for(i=1;i=9;i++)for(j=0;j=9;j++)for(k=0;k=9;k++)printf(%5d,100*i+10*j+k);return0;}(9).#includestdio.h#includemath.hintmain(){floata=-10,b=10,x,f1,f2,f;f1=(((2*a-4)*a+3)*a)-6;f2=(((2*b-4)*b+3)*b)-6;do{x=(a+b)/2;f=(((2*x-4)*x+3)*x)-6;if(f*f10){b=x;f2=f;}else{a=x;f1=f;}}while(fabs(f)=1e-6);printf(%6.2f\n,x);return0;}(10).#includestdio.h#includemath.hintmain(){intn=2;doubleeps,t,s=0,x;scanf(%lf%lf,&x,&eps);t=x;s=t;while(fabs(t)=eps){t=-t*(2*n-3)*x*x/(2*n-2);s=s+t/(2*n);n++;}printf(%d,%lf\n,n,s);return0;}(11).#includestdio.hintmain(){unsignedlongs,t=0,p=1;scanf(%u,&s);while(s!=0){if((s%10)%2!=0){t=t+(s%10)*p;p=p*10;}s=s/10;}printf(%u\n,t);return0;}5第4章习题参考答案1.单项选择题1-5DDDBD6-10BADCD11-14BDAB2.填空题(1)2(2)嵌套,递归(3)全局变量,局部变量,静态变量,动态变量(4)auto,static,register,extern(5)外部变量(6)编译,运行3.阅读程序,指出结果(1)15(2)5(3)5,4,3(4)i=5i=2i=2i=4i=2(5)求水仙花数(6)-5*5*5(7)30(8)0101112124.程序填空(1)floatfun(float,float),x+y,x-y,z+y,z-y(2)x,x*x+1(3)s=0,a=a+b5.编程题(1).#includestdio.hunsignedintfun(unsignedint);intmain(){unsignedints;scanf(%u,&s);printf(%u\n,fun(s));return0;}unsignedintfun(unsignedints){unsignedintp=0;while(s!=0){p=p+s%10;s=s/10;}returnp;}(2).#includestdio.h#includestdlib.h#includemath.hvoidf1(float,float,float,float);voidf2(float,float,float,float);6voidf3(float,float,float,float);intmain(){floata,b,c,d;scanf(%f%f%f,&a,&b,&c);if(a==0){printf(不是一元二次方程\n);exit(0);}d=b*b-4*a*c;if(d0)f1(a,b,c,d);elseif(d==0)f2(a,b,c,d);elsef3(a,b,c,d);return0;}voidf1(floata,floatb,floatc,floatd){floatx1,x2;{x1=(-b+sqrt(d))/(2*a);x2=(-b-sqrt(d))/(2*a);printf(%.2f,%.2f\n,x1,x2);}}voidf2(floata,floatb,floatc,floatd){floatx1,x2;{x1=-b/(2*a);x2=-b/(2*a);printf(%.2f,%.2f\n,x1,x2);}}voidf3(floata,floatb,floatc,floatd){floatx1,x2;{x1=-b/(2*a);x2=sqrt(-d)/(2*a);printf(%.2f+i*%.2f\n,x1,x2);printf(%.2f-i*%.2f\n,x1,x2);}}(3).#includestdio.hdoublep(int,double);intmain(){intn;doublex;do{scanf(%d,&n);}while(n0);scanf(%lf,&x);printf(%lf\n,p(n,x));return0;}doublep(intn,doublex){doublepn;if(n==0)pn=1;elseif(n==1)pn=x;elsepn=((2*n-1)*x*p(n-1,x)-(n-1)*p(n-2,x))/n;7returnpn;}(4).#includestdio.h#defineRATE0.053doublefun(float);voiddisplay(float,int);intmain(){floatdep;intseason;scanf(%f%d,&dep,&season);display(dep,season);return0;}doublefun(floatd){returnd*RATE;}voiddisplay(floatd,ints){inti;printf(季度利余额\n);printf(-------------------------------\n);for(i=1;i=s;i++){printf(%-4d%-.2f%-.2f\n,i,fun(d),fun(d)*i+d);printf(-------------------------------\n);}}(5).#includestdio.hdoublefun(void);intmain(){printf(%lf\n,fun());return0;}doublefun(void){doubles=0;intn=1;while((double)(2*n-1)/((2*n)*(2*n))1e

1 / 27
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功