C语言程序设计实用教程参考答案

上传人:博****1 文档编号:511835539 上传时间:2023-08-14 格式:DOC 页数:26 大小:50KB
返回 下载 相关 举报
C语言程序设计实用教程参考答案_第1页
第1页 / 共26页
C语言程序设计实用教程参考答案_第2页
第2页 / 共26页
C语言程序设计实用教程参考答案_第3页
第3页 / 共26页
C语言程序设计实用教程参考答案_第4页
第4页 / 共26页
C语言程序设计实用教程参考答案_第5页
第5页 / 共26页
点击查看更多>>
资源描述

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

1、第2章课后习题参考答案一、(略)二、单选题1、C 2、D 3、C 4、A 5、C 6、D 7、C 8、B 9、D 10、A 三、填空题1、 1 2、 880 3、 10000010 4、00001111 5、11110000 6、 3 .500000 0四、写程序运行结果1、 2,1 2、 0 3、 16 4、3 5、 1五、编程题解:设鸡有X只,兔有Y只,根据题意可得方程如下:x+y=a2x+4y=b解方程组可得到:x=(4*a-b)/2y=(b-2a)/s编程如下:#include #include main( ) int x,y,a,b; printf(“Please input two

2、 interger numbers:n”); scanf(“%d,%d”,&a,&b); x=(4*a-b)/2; y=(b-2*a)/2; printf(“There are %d chicken.n”,x); printf(“There are %d rabbit.n”,y);2、(题意看书上:求三角形面积)#include #include main( ) int a,b,c; float s ,area; printf(“Please input 3 numbers for triangle:n”); scanf(“%d,%d,%d”,&a,&b,&c); s=0.5*(a+b+c);

3、 area=sqrt(s*(s-a)*(s-b)*(s-c); printf(“area=%f”,area);第3章课后习题参考答案单选题B 2、B C 3、A 4、D 5、B 6、C 7、C 8、C 9、A 10、A 11、C 12、C 13、B 14、C 15、B 16、B写出下列程序的运行结果 1、 a=20,b=40,c=20 2、 23 3、68 4、a=%d ,b=%d 5、 1 65 1.5 6.5 6、a=3.140000,3.1400000e+00,3.140e+00,3.140e+00b=-3.141,-3.1415e+00,-3.1415e+00 7、x=4 y=11 8

4、 k=4 9 x=4.900000 y=4 10 * * * *填空题1、 (1) d,e (2) (ab) (3) (dc) 输出显示:max=7 2、 (1)k=1;break;(2)k=2;break;(3)k=3;break;(4)k=4;break;(5)k=5;break;3 4、(i%3=0)&(i%5=0)&(i%7=0) 5、i=0,j=0,n; scanf(“%d”,&n);四、编程题1.要求从大到小打印三个整数,a,b,c.main() int a,b,c,t; scanf(%d%d%d,&a,&b,&c); if(ab) t=a; a=b; b=t; if(ac) t=

5、a; a=c; c=t; if(bc) t=b; b=c; c=t; printf(big to small:%d %d %dn,a,b,c);2.编程求一元二次方程的根#include main() float a,b,c,disc,x1,x2,realpart,imagpart; printf(input canshu a,b,c); scanf(%f,%f,%f,&a,&b,&c); printf(The equation ); if(fabs(a)=1e-6) printf(is not a 2 ci fangcheng.); else disc=b*b-4*a*c; if(fabs(

6、disc)1e-6) x1=(-b+sqrt(disc)/(2*a); x2=(-b-sqrt(disc)/(2*a); printf(has distinct real roots:%f and %fn,x1,x2); else realpart=-b/2*a; imagpart=sqrt(-disc)/(2*a); printf(has complex roots:n); printf(%f+%fin,realpart,imagpart); printf(%f-%fin,realpart,imagpart); 3.main() float a,r,rate,bonus; printf(in

7、put a(jiangjin):); scanf(%f,&a); if(a=500&a=1000&a=2000&a6) t=6; switch(int)(t) case 0: rate=0; break; case 1: rate=(a-500+1)*0.05; break; case 2: case 3: rate=(a-1000+1)*0.08+500*0.05; break; case 4: case 5: rate=(a-2000+1)*0.1+1000*0.08+500*0.05; break; case 6: rate=(a-3000+1)*0.15+1000*0.1+1000*0

8、.08+500*0.05; break; bonus=a-rate; printf(rate=%f,bonus=%fn,rate,bonus);4.编程,将2000到3000年之间的闰年输出main() int y; for(y=2000;y=3000;y+) if(y%4=0&y%100!=0|y%400=0)printf(%d ,y); 5.从键盘输入若干字符,统计其中字母符号(区分大小写),数字符号和其他字符的个数。#include main() char c; int bletter=0,sletter=0,digit=0,other=0; printf(inpur some char

9、s:n); while(c=getchar()!=n) if(c=a&c=A&c=0&c=9) digit+; else other+; printf(bletter:%d,sletter:%d,digit:%d,other:%dn,bletter,sletter,digit,other);6、求阶乘的前20项的和 main( ) float s=0,t=1; int n ; for(n=1;n=20;n+) t=t*n;s=s+t;printf(“1!+2!+3!+.+20!=%en”,s);7.编程求所有的水仙花数。main() int i,j,k,n; for(n=100;n1000;n

10、+) i=n/100; j=n/10-i*10; k=n%10; if(i*i*i+j*j*j+k*k*k=n) printf(%4d,n); printf(n);8.(题意看书上)main() int i,j,k,n; for(n=200;n300;n+) i=n/100; j=n/10-i*10; k=n%10; if(i*j*k=42&i+j+k=12) printf(%4d,n); printf(n);9.编程计算1100之间能同时被3和4整除的所有的整数的和。main() int n,sum=0; clrscr(); for(n=1;n100;n+) if(n%3=0&n%4=0) printf(%d ,n); sum=sum+n; printf(nsum=%d,sum);10、编程计算1100之间所有的偶数的和。main( ) int n,s=0; for(n=1;n100;n+) if(n%2=0)s=s+n; printf(“s=%d”,s);11.(题意看书上)main() int t; printf(students number maybe:); for(t=500;t1000;t+)

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

当前位置:首页 > 高等教育 > 习题/试题

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