您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > C语言程序设计教程(第三版)课后习题参考答案张敏霞版
附录F课后题参考答案习题11.1填空题1.函数2.主函数main();主函数main()3.主函数main()4.函数首部;函数体5.{;}6.顺序结构;选择结构;循环结构7..c;.obj;.exe1.2思考题1.答:结构化程序设计是指,为使程序具有一个合理的结构以保证程序正确性而规定的一套如何进行程序设计的原则。顺序结构,选择结构,循环结构2.答:算法是对具体问题求解步骤的一种描述。计算机算法的表达工具通常采用以下几种方法:①用自然语言表示算法;②用流程图表示算法;③用伪代码表示算法;④用程序设计语言表示算法。3.略4.略5.略1.3编程题1.答:#includestdio.hmain(){floata=10,b=20,h=5,s;s=(a+b)*h/2;printf(s=%f,s);}2.答:#includestdio.hmain(){printf(******************************);printf(*helloworld*);printf(******************************);}C语言程序设计教程(第3版)270习题22.1单选题DBDCADCABBCA2.2填空题1.2.0000002.1;0.5000003.9;24.65.100;d6.(1)20(2)0(3)607.(1)10;6;4(2)6;9;15(3)3;60;838.55或'7'9.x=4;y=6;z=3;m=4632.3改错题(略)习题33.1单选题BDABCADCACBBA3.2填空题1.32.2613.104.2,1;互换a,b的值5.6.66.0037.78.5.0,4,c=3Enter9.i=10,j=20Enter10.(1)65(2)65,A(3)3.14,123.46(4)3.141600e+000,1.234560e+002(5)8765.432100(6)8.765432e+003附录F课后题参考答案27111.a=2b=5x=8.8y=76.34c1=65c2=9712.%d/%d;%d/%d=%.2f\n3.3改错题(略)3.4编程题1.答:#includestdio.hmain(){intx,y;scanf(%d%d,&x,&y);printf(\t\tx\ty\n);printf(十进制数\t%d\t%d\n,x,y);printf(八进制数\t%o\t%o\n,x,y);printf(十六进制数\t%X\t%x\n,x,y);}2.答:#includestdio.hmain(){charch;printf(请输入一个大写英文字母);scanf(%c,&ch);printf(大写英文字母是%c\n,ch);printf(它的前导字符是%c\n,ch-1);printf(它的后续字符是%c\n,ch+1);}3.答:#includestdio.hmain(){intx,a,b,c,y;printf(请输入一个三位整数\n);scanf(%d,&x);a=x/100;b=(x-a*100)/10;c=x%10;y=c*100+b*10+a;printf(反向输出该整数:%d\n,y);}}4.答:#includestdio.hmain(){inthour;doublesalary,salaryday;scanf(%d,%lf,&hour,&salaryday);salary=hour*salaryday-hour*salaryday*0.1;C语言程序设计教程(第3版)272printf(%8.2lf\n,salary);}5.答:#includestdio.hmain(){inta,b,c,t;printf(请输入三个整数\n);scanf(%d%d%d,&a,&b,&c);printf(交换前a=%d,b=%d,c=%d\n,a,b,c);t=a;a=c;c=b;b=t;printf(交换后a=%d,b=%d,c=%d\n,a,b,c);}习题44.1单选题BADDDACBBBBA4.2填空题1.12.(1)a0||b0(2)x0&&x=10(3)a==1.5&&b==1.5&&c==1.5(4)pa||pb||pc3.(1)0(2)1(3)1(4)0(5)14.c=15.46.17.5,0,38.59.12310.(cvb=='y'||cvb=='Y')&&(work=3||college=='y'||college=='Y')&&age=354.3改错题(略)4.4编程题1.答#includestdio.h#includemath.hmain(){doublea,b,c,p,area;scanf(%lf%lf%lf,&a,&b,&c);printf(三角形的三边为:%.llf,%.1lf,%.1lf\n,a,b,c);if(a+bc&&a+cb&&b+ca){p=(a+b+c)/2;附录F课后题参考答案273area=sqrt(p*(p-a)*(p-b)*(p-c));printf(三角形的面积为%.2lf\n,area);}elseprintf(不能构成三角形\n);}2.答:#includestdio.hmain(){intx,y;scanf(%d,%d,&x,&y);if(x*x+y*y1000)printf(%d\n,(x*x+y*y)/100);elseprintf(%d\n,x+y);}3.答:#includestdio.h#includemath.hmain(){doublex,y;scanf(%lf,&x);if(x-2)y=x*x-sin(x);elseif(x=2)y=pow(2,x)+x;elsey=sqrt(x*x+x+1);printf(x=%.2lfy=%.2lf\n,x,y);}4.答:#includestdio.hmain(){longge,shi,qian,wan,x;scanf(%ld,&x);wan=x/10000;qian=x%10000/1000;shi=x%100/10;ge=x%10;if(ge==wan&&shi==qian)/*个位等于万位并且十位等于千位*/printf(thisnumberisahuiwen\n);elseprintf(thisnumberisnotahuiwen\n);}5.答:#includestdio.hmain(){floatp,w,s,d,f;C语言程序设计教程(第3版)274scanf(%f,%,%f,p,s,w);if(s3000)d=0.15elseif(s=2000)d=0.1;elseif(s=1000)d=0.08;elseif(s=500)d=0.05;elseif(s=250)d=0.02;elsed=0f=p*w*s*(1-d);printf(%f,f);}6.答:#includestdio.hmain(){intyear,money;charx;printf(是否是本公司产品(y/n):);scanf(%c,&x);if(x=='y'||x=='Y'){printf(产品使用的年限:);scanf(%d,&year);if(year=1)money=0;elseif(year8)money=50;elsemoney=100;printf(产品保修额是:%d\n,money);}else{money=200;printf(不是本公司产品,产品保修额是:%d\n,money);}}7.答:#includestdio.hmain(){intmoney,num1,num2;printf(请输入取款额(≤2000):);scanf(%d,&money);if(money2000)printf(请输入取款额数≤2000!\n);elseif(money%50==0){num1=money/100;num2=(money-num1*100)/50;printf(需支付100元:%d张\n,num1);printf(需支付50元:%d张\n,num2);}elseprintf(输入钱数必须是50的倍数!\n);}附录F课后题参考答案275习题55.1单选题CDABAABDDBDBCB5.2填空题1.202.3333.(1)i10或i=9(2)j%3!=04.(1)flag*(float)k/(k+1)或1.0*flag*k/(k+1)(2)flag=-flag5.(1)max=x(2)x!=1(3)scanf(%d,&x)6.(1)x=9或x10(2)y=9x5.3改错题(略)5.4编程题1.答:(1)for循环,其他略#includestdio.hmain(){inti,s=0;for(i=1;i=100;i++)s+=i*i;printf(%d\n,s);}(2)for循环,其他略#includestdio.hmain(){inti=1,p=1;doubles=1;do{s+=1.0/p;p*=++i;}while(1.0/p1e-6);printf(%lf,s);}2.答:#includestdio.hmain(){intm,n,t,a,b;scanf(%d,%d,&m,&n);if(mn)C语言程序设计教程(第3版)276{t=m;m=n;n=t;}a=m;b=n;t=m%n;while(t){m=n;n=t;t=m%n;}printf(%d,n);}3.答:#includestdio.hmain(){intx,y,s=1;scanf(%d,%d,&x,&y);for(;y0;y--)s*=x;printf(%d,%d,%d\n,s%10,s/10%10,s/100%10);}4.答:#includestdio.hmain(){intx,y,z;for(x=1;x20;x++)for(y=1;y33;y++){z=100-x-y;if((z%3)==0&&(5*x+3*y+z/3)==100)printf(x=%d,y=%d,z=%d\n,x,y,z);}}5.答:(a)#includestdio.hmain(){intj,k;for(j=1;j=4;j++){for(k=1;k=4-j;k++)printf();printf(****);printf(\n);}}(b)#includestdio.hmain(){intj,k;for(j=1;j=4;j++){for(k=1;k=4-j;k++)printf();for(k=1;k=2*j-1;k++)printf(*);printf(\n);}}附录F课后题参考答案2776.答:程序分析:利用for循环控制在100~999之间,对每个数分解出个位、十位、百位。#includestdio.hmain(){inti,j,k,n;printf(waterflower'numberis:);for(n=100;n1000;n++){i=n/100;/*分解出百位*/j=n/10%10;/*分解出十位*/k=n%10;/*分解出个位*/if(n==i*i*i+j*j*j+k*k*k){printf(%-5d,n);}}printf(\n);}7.答:#includestdio.hmain(){intx;for(x=1000;x=3;x--)if(x%3==1&&x%5==2&&x%7==3){printf(该校的学生人数是:%d人\n,x);break;}}8.答:#includestdio.hmain(){intx=12,i=1;while(1){if((x+20+i)==2*(x+i))break;i++;}printf(小明母亲在%d年后比小明的年龄大一倍\n,i);printf(那时小明年龄是:%d岁,小明母亲年龄是:%d岁\n,x+i,x+20+i);}习题66.1单选题DBCCBBDCC语言程序设计教程(
本文标题:C语言程序设计教程(第三版)课后习题参考答案张敏霞版
链接地址:https://www.777doc.com/doc-2908192 .html