文档详情

C课后习题参考答案.doc

发布:2017-09-15约3.04万字共35页下载文档
文本预览下载声明
习 题 参 考 答 案 习 题 1 一、选择题 1、B 2、C 3、B 4、D 5、A 6、B 7、C 1、源程序文件 c 2、obj 3、可执行文件 exe 4、机器语言 高级语言 三、解答题 略 四、编程题 1、 main() { printf(“Hello! Welcome to China!”); } 2、 main() {int x; scanf(“%d”,x); if(x=20x1000) printf(“x=%d”,x); else printf(“Input error!”); } 题 2 一、选择题 1、C  2、A  3、B  4、D  5、 A 6、D  7、B  8、B 9、B   10、D 11、D 12、B 13、A 14、B 15、C 二、填空题 1、整型、实型、字符型 2、用户标识符、关键字标识符 3、存储单元、符号地址、内存地址 4、十、十六、八 5、double(双精度型) 6、 8 7、5.500000 8、a=-32768 9、+0017,021,0x11 三、写程序运行结果 3257 57 7.88, -345.12,7.8765,-345.1230 7.87654e+00, -3.5e+02 a,97,141,61 1234,2322,4d2 CHINESE, CHI 四、scanf函数的使用 a=3 b=7 8.5 71.82 A a 五、用scanf函数输入数据 20Aa1.5-3.75 123.45,67.8 注意,其中123.45可以是任意实数,因为该值将被跳过,不用于赋值。 习 题 3 一、选择题 1. C 2. B 3. D 4. D 二、填空题 基本概念题 1. 2 2. 2 3. 1 阅读程序写出运行结果题 4. 1.00 5. 1,0,1 6. 9,11,9,10 三、写出下面表达式运算后a的值,设原来a=12。 (1)24 (2)10 (3)60 (4)0 (5)0 (6)0 习 题 4 一、选择题 1、B 2、D 3、B 4、D 5、A 6、C 二、填空题 1、1,0,1 2、1,2,3 3、ch1=′A′ch1=′Z′ ch1=ch1-32; 三、编程题 1、从键盘输入三个数,然后按照由小到大的顺序输出。要求,设三个数放在变量a、b、c中,最后仍然按照a、b、c的顺序输出。 #include stdio.h main() {int a,b,c,t; scanf(“%d,%d,%d”,a,b,c); if(ab) {t=a; a=b; b=t;} if(ac) {t=a; a=c; c=t;} if(bc) {t=b; b=c; c=t;} printf(“%d,%d,%d\n”,a,b,c); } 2、编写程序根据以下的函数关系,对输入的x值输出相应的y值。 x y 2x=10 x(x+2) -1x=2 2x X=-1 x-1 #include stdio.h main() {float x,y; scanf(“%f”,x); if(x=-1) y=x-1; else if(x=2) y=2*x; else if(x=10) y=x*(x+2); else printf(“Error!\n”); printf(“y=%f\n”,y); } 3、求一元二次方程ax2+bx+c=0的解。 #include math.h main() {float a,b,c,d,disc,x1,x2,realpart,imagpart; scanf(“%f,%f,%f”,a,b,c); if(fabs(a)=1e-6) Printf(is not a quadratic); else {disc=b*b-4*a*c; if(fabs(disc)=1e-6) printf(“has two equal roots:%8.4\n”,-b/(2*a)); else if(disc1e-6) {x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a); printf(“has distinct real roots:%8.4f and %8.4f\n”,x1,x2); } else {
显示全部
相似文档