C语言程序设计(科学出版社)第4章 课后习题参考答案

上传人:仙*** 文档编号:135679301 上传时间:2022-08-15 格式:DOC 页数:6 大小:56KB
收藏 版权申诉 举报 下载
C语言程序设计(科学出版社)第4章 课后习题参考答案_第1页
第1页 / 共6页
C语言程序设计(科学出版社)第4章 课后习题参考答案_第2页
第2页 / 共6页
C语言程序设计(科学出版社)第4章 课后习题参考答案_第3页
第3页 / 共6页
资源描述:

《C语言程序设计(科学出版社)第4章 课后习题参考答案》由会员分享,可在线阅读,更多相关《C语言程序设计(科学出版社)第4章 课后习题参考答案(6页珍藏版)》请在装配图网上搜索。

1、《C语言程序设计》习题参考答案 第4章 习题参考答案 1 判断题 1 2 3 4 5 6 × × √ √ × √ 2 选择题 1 2 3 4 5 6 7 8 B B B B D A B B 3 程序阅读题 (1) 105 (2) a=8 (3) abc123DEF (4) 4 程序填空题 (1) ch ch==')' count-- count==0 count>0 (2) div=n div— (3) min=mark min=mark max=mark sum+

2、=mark 5 编程题 (1) #include void main( ) { int x,y; printf("Enter the X,Y=?\n"); scanf("%d,%d",&x,&y); if(x>0 && y>0) printf("(%d,%d)是第一像限\n",x,y); else if(x>0 && y<0) printf("(%d,%d)是第四像限\n",x,y); else if(x<0 && y>0) printf("(%d,%d

3、)是第三像限\n",x,y); else if(x<0 && y<0) printf("(%d,%d)是第二像限\n",x,y); else if(x>0 && y==0) printf("(%d,%d)在X轴正方向\n",x,y); else if(x<0 && y==0) printf("(%d,%d)在X轴负方向\n",x,y); else if(x==0 && y>0) printf("(%d,%d)在Y轴正方向\n",x,y); else if(x==0 && y<0)

4、 printf("(%d,%d)在Y轴负方向\n",x,y); else printf("(%d,%d)为坐标原点\n",x,y); } (2) #include #include main() { float a, b, c, x, s; printf("Input a, b and c:"); scanf("%f%f%f", &a, &b, &c); if(a+b<=c || a+c<=b || b+c<=a) printf("Error!\n"); els

5、e{ x=(a+b+c)/2; s=sqrt(x*(x-a)*(x-b)*(x-c)); printf("area=%f\n", s); } } (3) 程序代码如下: #include void main() { float salary, tax; int ntax; printf("\nPlease enter a salary="); scanf("%f",&salary); ntax=salary/500; if (ntax>=10) ntax=10; sw

6、itch(ntax) { case 0: case 1: tax=0;break; case 2: tax=(salary-1000)*0.05;break; case 3:case 4: tax=500*0.05+(salary-1500)*0.1;break; case 5:case 6: tax=500*0.05+1000*0.1+(salary-2500)*0.15;break; case 7:case 8:case 9:

7、 tax=500*0.05+1000*0.1+1000*0.15+(salary-3500)*0.20;break; case 10: tax=500*0.05+1000*0.1+1000*0.15+1500*0.20+(salary-5000)*0.30; } printf("\nThe tax=%10.2f\n",tax); } (4)方法一 #include #include main() { int i=1; float t=-1, s=0;

8、 do{ t= -t/i; s=s+t; i=i+1; }while(fabs(t)>1e-6); printf("s=%f\n", s); } 方法二 #include void main() { int i=1,sign=1; float t=1.0, s=0.0; while(1.0/t>1e-6) { t= t*i; s=s+sign/t; i=i+1; sign=-sign; }; printf("s=%f\n",

9、s); } (5)方法一: #include main() { int i, a, b, c; for(i=100; i<=999; i++) { a=i /100; b=i/10%10; c=i%10; if(i==a*a*a+b*b*b+c*c*c) printf("%d\n", i); } } 方法二: #include void main() { int i, a, b, c; for(a=1; a<=9; a++) for(b

10、=0; b<=9; b++) for(c=0; c<=9; c++) { i=a*100+b*10+c; if(i==a*a*a+b*b*b+c*c*c) printf("%d\n", i); } } (6) #include main() { int i, j; for(i=1; i<=4; i++) { for(j=1; j<=6-i; j++) putchar(' '); for(j=1; j<=i*2-1; j++) pr

11、intf("%c", 65+i-1); printf("\n"); } for(i=3; i>=1; i--) { for(j=1; j<=6-i; j++) putchar(' '); for(j=1; j<=i*2-1; j++) printf("%c", 65+i-1); printf("\n"); } } (7) #include main() { int a, b, c; for(a=0; a<=20; a++) for(b=0; b<=33; b++

12、) { c=100-a-b; if(a*5+b*3+c/3.0==100) printf("%d, %d, %d\n", a, b, c); } } (8) #include #include main() { float x, x0, a; scanf("%f", &a); x=a; do{ x0=x; x=2/3.0*x0+a/(3*x0*x0); }while(fabs(x-x0)>1e-6); printf("x=%

13、f\n", x); } (9) #include #include main() { float pi, pi0; int i=1 pi=2; do{ pi0=pi; pi=pi*(2.0*i/(2.0*i-1))*(2.0*i/(2.0*i+1)); i=i+1; }while(fabs(pi-pi0)>1e-6); printf("pi=%f\n", pi); } (10) #include void main() { int i,j,s;

14、 for(i=6;i<=1000;i++) { s=1; for(j=2;j<=i/2;j++) if(i%j==0) s+=j; if(s==i) /*判断是否是合数*/ { printf("%d=1",i); /* 打印输出合数及=1*/ for(j=2;j<=i/2;j++) /* 打印输出各因子*/ if(i%j==0) printf("+%d",j); printf("\n"); } } } (11) #include #include void main() { int x, y,z,k; k=sqrt(2000); for(x=0;x<=k;x++) for(y=0;y<=k;y++) for(z=0;z<=k;z++) if(x*x+y*y+z*z==2000) printf("%d,%d,%d\n",x,y,z); }

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

相关资源

更多
正为您匹配相似的精品文档
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!