CC语言课后习题答案

上传人:飞*** 文档编号:32958050 上传时间:2018-02-13 格式:DOC 页数:18 大小:401.92KB
返回 下载 相关 举报
CC语言课后习题答案_第1页
第1页 / 共18页
CC语言课后习题答案_第2页
第2页 / 共18页
CC语言课后习题答案_第3页
第3页 / 共18页
CC语言课后习题答案_第4页
第4页 / 共18页
CC语言课后习题答案_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《CC语言课后习题答案》由会员分享,可在线阅读,更多相关《CC语言课后习题答案(18页珍藏版)》请在金锄头文库上搜索。

1、习题三3.2 假设用 2 个字节存放(1)10 0000 0000 0000 1010 (2)32 0000 0000 0010 0000 (3)75 0000 0000 0100 1011(4)-671 1111 1101 0110 0001 (5)-111 1111 1111 1001 0001 (6)2483 0000 1001 1011 0011(7)-28654 1001 0000 0001 0010 (8)21003 0101 0010 0000 1011 举例:-671 的补码求解过程:671 的二进制数为:0000 0010 1001 1111,取反加 1 后得:1111 11

2、01 0110 0001,即为-671 的补码表示。3.3 3 3.4 (1)0 (2)1 (3)3 (4)3 (5)8 3.5 (3) 3.6 (2) (题目中 c2 应为Y)-4 3.7(2) 3.9 (1)2.5 (2)3.5-4 3.10 (1) 24 (2)10 (3)60 (4)0 (5)0 (6)03.8 程序应修改为: 3.8 输出结果如下:#include (1)1void main() (2)1 int x,y,z; x=1,y=2x=y=z=1; (3)2printf(1)%dn,x=y=x)?1:0);printf(5)%dn,z=y习题四4.1 #include ma

3、in() printf(1 2 3 4n);printf(%d %d %d %dn,1,2,3,4);printf(1 ); printf(2 ); printf(3 ); printf(4n);4.3#include main() long n; int n1,n2,n3,n4,n5;printf(Input nmain() char c1,c2;printf(Input a lower letter (cz): ); c1=getchar();c2=c1-32;printf(Five letters centred on %c are %c%c%c%c%cn,c2,c2-2,c2-1,c2

4、,c2+1,c2+2);4.74.2#include main() int n,n0,n1,n2,n3;printf(Input nmain() float f,c;printf(Input f: ); scanf(%f,c=5.0/9*(f-32);printf(370F: %.2f, 370C: %.2fn,f,c);4.6 #include #define Pi 3.14main() float r,h,v;printf(Input r,h: ); scanf(%f%f,v=PI*r*r*h;printf(V=%gn,v); 4.8#include main() char c;c=get

5、char();printf(%c%c%cn,32,32,c);printf(%c%c%c%cn,32,c+1,c+1,c+1);printf(%c%c%c%c%cn,c+2,c+2,c+2,c+2,c+2);#include main() float apple,pear,banana,orange,sum;printf(Input sale amount of apples,pears,bananas,oranges: n); scanf(%f%f%f%f,sum=apple*5.0+pear*3.4+banana*4+orange*2.4;printf(total : %gn,sum);习

6、题五5.1 求一元二次方程的根#include #include main() float a,b,c,disc,x,x1,x2,p,q;printf(Input a,b,c: ); scanf(%f%f%f,if(a=0) /*一次方程的求根*/if(b=0) printf(Input error.n); else x=-c/b; printf(equation: %gx+%g=0 its root : %gn,b,c,x); else /*二次方程的求根*/ printf(equation: %gx2+%gx+%g=0 : ,a,b,c);disc=b*b-4*a*c;if(disc0)

7、/*求两个不相等的实根*/ p=-b/(2*a); q=sqrt(disc)/(2*a);x1=p+q; x2=p-q;printf(two unequal real roots: x1=%g,x2=%gn,x1,x2);else if(disc=0) /*求两个相等的实根*/ x1=x2=-b/(2*a);printf(two equal real roots: x1=x2=%gn,x1);else /*求虚根*/ p=-b/(2*a); q=sqrt(-disc)/(2*a);printf(two image roots: x1=%g+%gi, x2=%g-%gin,p,q,p,q);5.

8、3 五位整数中有几个 7#include main() long n; int n1,n2,n3,n4,n5,k=0;printf(Input n(1000099999) : ); scanf(%ld,n1=n%10; n2=n/10%10; n3=n/100%10; n4=n/1000%10; n5=n/10000;if(n1=7) k+; if(n2=7) k+;if(n3=7) k+;if(n4=7) k+;if(n5=7) k+;printf(%ld has %d 7s.n,n,k);5.6 三边能否构成三角形#include 5.2 月份的英文名及天数#include main()

9、int month;printf(Input month: ); scanf(%d,switch(month) case 1: printf(January has 31 days.n); break;case 2: printf(February has 28 or 29 days.n); break;case 3: printf(March has 31 days.n); break;case 4: printf(April has 30 days.n); break; case 5: printf(May has 31 days.n); break;case 6: printf(June

10、 has 30 days.n); break;case 7: printf(July has 31 days.n); break;case 8: printf(August has 31 days.n); break;case 9: printf(September has 30 days.n); break;case 10: printf(October has 31 days.n); break;case 11: printf(November has 30 days.n); break;case 12: printf(December has 31 days.n); break;defa

11、lult: printf(Input error.n);5.4 从键盘输入 3 位整数,找出居中的数字输出。#include main() int n;printf(Input n(100999): ); scanf(%d,printf(Output the center digit: %dn,n/10%10);5.5 求闰年#include main() int a,b,c,t;printf(Input 3 numbers: ); scanf(%d%d%d,if(ab) t=a; a=b; b=t; if(ac) t=a; a=c; c=t; if(bc) t=b; b=c; c=t; pr

12、intf(%dmain() int year;printf(Input a year: ); scanf(%d,if(!(year%4)&year%100|!(year%400) printf(The year %d is a leap year.n,year);else printf(The year %d isnt a leap year.n,year);main() int a,b,c;printf(Input 3 number: ); scanf(%d%d%d,if(a=0|b=0|c=0) printf(Input error.n);elseif(a+bc|a+cb|b+ca) pr

13、intf(They can be a triangle.ln);else printf(They cant be a triangle.n);5.8 12 小时计时#include main() int hour,minute,second;printf(Input time: ); scanf(%d%d%d,&hour,&minute,&second):if(hour=12) printf(Time is %d %d %d PM.n,hour-12,minute,second);else printf(Time is %d %d %d AMn,hour,minute,second);5.9

14、成绩分类#include main() float score;printf(Input score: ); scanf(%f,if(score=85) printf(Very good.n); else if(score=60) printf(Good.n);else printf(Not good.n);习题六6.1 鸡兔同笼#include main() int i,j;for(i=1;imain() int n,k=0;for(n=1; ; n+)if(n%3=2&n%5=3&n%7=4) printf(%d ,n); if(+k=10) break; printf(n); 运行结果:6.3 方法二:#include 5.10 函数计算 #include #include main() float x,y,z;printf(Input x: ); scanf(%f,if(xmain() int i;for(i=1; ; i+)y=70+i; z=20+i+15+i+5+i;if(y=z) printf(after %d years.n,i);bre

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 其它办公文档

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