c++语言程序设计答案

上传人:zw****58 文档编号:40893580 上传时间:2018-05-27 格式:DOC 页数:37 大小:338.50KB
返回 下载 相关 举报
c++语言程序设计答案_第1页
第1页 / 共37页
c++语言程序设计答案_第2页
第2页 / 共37页
c++语言程序设计答案_第3页
第3页 / 共37页
c++语言程序设计答案_第4页
第4页 / 共37页
c++语言程序设计答案_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《c++语言程序设计答案》由会员分享,可在线阅读,更多相关《c++语言程序设计答案(37页珍藏版)》请在金锄头文库上搜索。

1、C+语言程序设计习题参考答案教材名称教材名称 :C+C+语言程序设计语言程序设计 主主 编编 :李宁 出出 版版 社社 :中央广播电视大学出版社 版版 本本 :2000 年 7 月第 1 版第一章第一章第一章第一章 C+C+语言概述语言概述 自测题 P2 1.1-1 C P8 1.2-1 形式参数表 1.2-2 main 1.2-3 ; 1.2-4 1.2-5 main 1.2-6 显示器 输出流 1.2-7 键盘 输入流 1.2-8 头文件 1.2-9 int f( ); 1.2-10 124 1.2-11 1.2-12 1.2-13 1.2-14 1.2-15 1.2-16 1.2-17

2、ABCFG 1.2-18 D 1.2-19 DP11 1.3-1 OBJ 1.3-2 source.cpp 习题一习题一 (P12) 1-11-11C 2类型修饰符 3main4语句以分号(;)结束 5 6 8. .h 9source. .obj10Main 11char * Hi(const char *); 1233 1-21-21 2 3 4 5 6 7 8 1-31-31ABFI 2D 3ABCD 4B 1-41-4# include void main( ) cout void main() int i,j,k; cout ijk; cout y+3 2.8-2 x!=3 2. 7

3、3. 17 4. D:MyDirMyFile.Dat 5. C F 6. 48+n U 或 char(48+n) U 或 n+0 U 7. Jun thisMonth+1 ( 说明:VC+不支持枚举数据参加算术运算,此例无法编译) 8. ( 说明:题目有错,cin m; 编译出错,C+不支持枚举数据输入) 9. 12.3456 9.87653e3 10. 3.66667 4.0 4 11. 57 45.0 G 12. 92 13. Whats your name? 14. 77 15. 2 44 3 16. 7 4 3 17. 3 1 18. 6 10 19. 3 7 20. 5 2 21.

4、f=+p+5; 22. f=p-5; 23. x+y=3 24. x=-5 25. a*a*a+3*a*a*a*b+3*a*b*b+b*b*b 26. 1.0/2*a*sqrt(b+2*c)/5) 27. IsMale Age=50|IsMale 2-32-4 1. B 2. A 3. AB 4. B 5. A6. ABCD 7. CEFHI 8. CEFGHJ 9. C 10. C11. A 12. AB 13. C 2-5 / P50 习题 2-5# include # include void main() double a,r;cout a;r=1.0/2*a*sqrt(10+2*sq

5、rt(5)/5);cout # include void main() double a,b,c,area,s; cout abc; s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c);cout # include void main() double x1,y1,z1,x2,y2,z2,d; cout x1y1z1; cout x2y2z2; d=sqrt(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1);cout =1 i- ) cout =1 cout weekday; if (weekday=0) cout

6、void main() int a,b,c,d,max; cout abcd;max=a; if (maxvoid main() int a,b,c,d,temp; cout abcd; cout b) temp=a; a=b; b=temp; if (ac) temp=a; a=c; c=temp; if (ad) temp=a; a=d; d=temp; / 求第二小数存入 b if (bc) temp=b; b=c; c=temp; if (bd) temp=b; b=d; d=temp; / 求第三小的数存入 c if (cd) temp=c; c=d; d=temp; cout vo

7、id main() cout void main() int a=1,b=2;double s=0,p; for (int i=1; i # define N 15 void main() int n;long double s=0.0L,fact=1.0L; for (n=1; nvoid main() int n1=1,n2=1,n=n1+n2,couter=2; / n1,n2 相邻二项的分母,cout 统计项数double s=2.0,s0; while (s0=1.0/n)=0.000001) s+=s0; n1=n2; n2=n; n=n1+n2; couter+; coutvoi

8、d main() int n=2,d=1,k=2; / k 统计项数double s=2.0,s0; while (s0=1.0/n)=0.000001) s+=s0; n+=d;d=n-d; k+; coutvoid main() for (int i=1; ivoid main() cout void main() int i; cout # include void main() double x; cout x; int i=1; double n=-x*x,d=1.0*2.0,s=1.0,s0; while (fabs(s0=n/d)=0.000001) s+=s0; i+; n*=

9、(-x*x); d*=(i+i)*(i+i-1); cout 0)cout 0 )cout 0)cout # define SIZE 10void main() int aSIZE;int temp,i,max,min; cout a0; max=min=0; / 存放最大数和最小数的下标 for (i=1; iai; if (aiamax) max=i; / 保存当前最大数的下标 if (aivoid main() int a=23,25,13,68,3,44,11,7,55,36; const int SIZE=sizeof(a)/sizeof(a0); / 数组 a 的元素个数int t

10、emp,i; cout ak) k=j;temp=ai; ai=ak; ak=temp; / 交换 cout void main() int a=23,25,13,68,3,44,11,7,55,36; const int SIZE=sizeof(a)/sizeof(a0); / 数组 a 的元素个数int temp,i; cout ak) k=j;temp=ai; ai=ak; ak=temp; / 交换 cout # define SIZE 20void main() int aSIZE,i;cout ai; while (aivoid main() int a=23,25,13,68,3

11、,44,11,7,55,36; const int SIZE=sizeof(a)/sizeof(a0); / 数组 a 的元素个数int i,number;cout number; cout # define SIZE 5void main() int aSIZESIZE; int i,j,sum=0;cout aij;cout # include # define SIZE 10void main() double dataSIZESIZE; int i,j,size;cout size; if (size10) cout dataij;/ 输出行列式 cout u) ) u=abs(aij

12、); if (u # include # define SIZE 80void main() char sSIZE; cout # include void main() cout # include # define SIZE 80void main() char sSIZE;cout 100 或 void ff(double d);5.3-2 A 5.3-3 C 5.3-4 DP128 5.4-1 8 3 5.4-2 CD 5.4-3 ABP131 5.6-1 数量 类型 5.6-2 ADP134 5.7-1 static 5.7-2 局部 5.7-3 extern double var;5.7-4 C 5.7-5 D 5.7-6 D5.7-7 D 5.7-8 DEP139 5.8-1 template 5.8-2 常规 虚拟类型 常规5.8-3 template Type cubic

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 教育学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号