C语言程序设计(谭浩强)第四版_课后答案.pdf

上传人:奔*** 文档编号:89651014 上传时间:2023-05-08 格式:PDF 页数:171 大小:7.72MB
返回 下载 相关 举报
C语言程序设计(谭浩强)第四版_课后答案.pdf_第1页
第1页 / 共171页
C语言程序设计(谭浩强)第四版_课后答案.pdf_第2页
第2页 / 共171页
点击查看更多>>
资源描述

《C语言程序设计(谭浩强)第四版_课后答案.pdf》由会员分享,可在线阅读,更多相关《C语言程序设计(谭浩强)第四版_课后答案.pdf(171页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、c语言程序设计(谭浩强)第四版.课后答案第一章程序设计和C 语 言【第 1 5页】1-5t t i n c l u d e i n t m ai n ()p r i n t f (*n n);p r i n t f C V e r y Go o d!n n );p r i n t f (*n);r e t u r n 0;)1-6#i n c l u d e i n t m ai n()i n t a,b,c,m ax;p r i n t f(p l e as e i n p u t a,b,c:n );s c an f (d,%d,%d,&a,&b,&c);m ax 二 a;i f (m a

2、x b)m ax=b;i f (m ax c)m ax=c;p r i n t f CT h e l ar g e s t n u m be r i s%d n ,m ax);r e t u r n 0;第2章算法程 序 的 灵 魂【第3 6页】暂无答案第3章最简单的C程序设计顺 序 程 序 设 计【第8 2页】3-1i n c l u d e t t i n c l u d e i n t m ai n()f l o at p,r,n;r=0.1;n=1 0;p=p o w(l+r,n);p r i n t f(p=%f n,p);r e t u r n 0;3-2-1#i n c l u

3、d e#i n c l u d e i n t m ai n()f l o at r 5,r 3,r 2,r l,r O,p,p l,p 2,p 3,p 4,p 5;p=1 000;r 5=0.0585;r 3=0.054;r 2=0.0468;r l=0.041 4;r O=O.0072;p l=p*(l+r 5)*5);/次存 5 年期p 2=p*(l+2*r 2)*(l+3*r 3);先存2年期,到期后将本息再存3年期p 3=p*(l+3*r 3)*(l+2*r 2);先 存3年期,到期后将本息再存2年期p 4=p*p o w(l+r l,5);存1年期,到期后将本息存再存1年期,连续存

4、5次p 5=p*p o w(l+r 0/4,4*5);存活期存款。活期利息每一季度结 算 次p r i n t f(p l=%f n,p l);输出按第1方案得到的本息和p r i n t f (p 2=%f n,p 2);/输出按第2方案得到的本息和p r i n t f (p 3=%f n”,p 3);/输出按第3方案得到的本息和p r i n t f (p 4=%f n”,p 4);/输出按第4方案得到的本息和p r i n t f (,p 5=%f n/,,p 5);/输出按第5方案得到的本息和r e t u r n 0;3-2-2i t i n c l u d e S i n c l

5、 u d e i n t m ai n()d o u bl e r 5,r 3,r 2,r l,r O,p,p l,p 2,p 3,p 4,p 5;p=1 000;r 5=0.0585;r 3=0.054;r 2=0.0468;r l=0.041 4;r O=O.0072;p l=p*(l+r 5)*5);/次存 5 年期p 2=p*(l+2*r 2)*(l+3*r 3);先存2年期,到期后将本息再存3年期p 3=p*(l+3*r 3)*(l+2*r 2);先 存3年期,到期后将本息再存2年期p 4=p*p o w(l+r l,5);存1年期,到期后将本息存再存1年期,连续存5次p 5=p*p

6、 o w(l+r 0/4,4*5);存活期存款。活期利息每一季度结 算 次p r i n t f (/zp l=%f n/,p l);/输出按第 1 方案得到的本息和 p r i n t f (p 2=%f n,p 2);输出按第2方案得到的本息和p r i n t f (p 3=%f n”,p 3);输出按第3方案得到的木息和p r i n t f (,/p 4=%f n,/,p 4);/输出按第4方案得到的本息和p r i n t f Cp 5=%f n,/,p 5);/输出按第5方案得到的本息和r e t u r n 0;)3-2-3#i n c l u d e#i n c l u d

7、e i n t m ai n()f l o at r 5,r 3,r 2,r l,r O,p,p l,p 2,p 3,p 4,p 5;p=1 000;r 5=0.0585;r 3=0.054;r 2=0.0468;r l=0.041 4;r 0=0.0072;p l=p*(l+r 5)*5);/一次存 5 年期p 2=p*(l+2*r 2)*(l+3*r 3);先 存 2 年期,到期后将本息再存3 年期p 3=p*(l+3*r 3)*(l+2*r 2);先存3 年期,到期后将本息再存2 年期p 4=p*p o w(l+r l,5);存 1 年期,到期后将本息存再存1 年 期,连 续 存 5 次

8、p 5=p*p o w(l+r 0/4,4*5);存活期存款。活期利息每一季度结算一次p r i n t f Cp l=%1 0.2f n,p l);/输出按第1 方案得到的本息和p r i n t f(p 2=%1 0.2f n”,p 2);输出按第2 方案得到的本息和p r i n t f(p 3=%1 0.2f n,p 3);输出按第3 方案得到的本息和p r i n t f Cp 4=%1 0.2f n/,,p 4);/输出按第4 方案得到的本息和p r i n t f(p 5=M 0.2f n”,p 5);/输出按第5 方案得到的本息和r e t u r n 0;)3-3.t t i

9、 n c l u d e i t i n c l u d e i n t m ai n()f l o at d=300000,p=6000,r=0.01,m;m=l o g l 0(p/(p-d*r)/l o g l O(1+r);p r i n t f (z zm=%6.2f n,m);r e t u r n 0;3-4#i n c l u d e i n t m ai n()i n t c l,c 2;c l=1 97;c 2=1 98;p r i n t f (,zc l=%c,c 2=%c n,z,c l,c 2);p r i n t f (c l=%d,c 2=%d n,z,c l,

10、c 2);r e t u r n 0;)3-5#i n c l u d e i n t m ai n ()i n t a,b;f l o at x,y;c h ar c l,c 2;s c an f C,a=%d b=%d,&a,&b);s c an f (f%e,z,&x,&y);s c an f(%c%c”,&c l,&c 2);p r i n t f (,a=%d,b=%d,x=%f,y=%f,c l=%c,c 2=%c n”,a,b,x,y,c l,c 2);r e t u r n 0;)3-6f t i n c l u d e i n t m ai n()c h ar c l=C,c

11、2=f h,c3=f i,c 4=n,c 5=a;c l=c l+4;c 2=c 2+4;c 3=c 3+4;c 4=c 4+4;c 5=c 5+4;p r i n t f (z,p as s w o r i s%c%c%c%c%c nz,,c l,c 2,c 3,c 4,c 5);r e t u r n 0;3-7i n c l u d e i n t m ai n ()f l o at h,r,1,s,s q,v q,v z;f l o at p i=3.1 41 526;p r i n t f (请输入圆半径r,圆柱高h :);s c an f C7%f,%f&r,&h);要求输入圆半径

12、r和圆柱高h l=2*p i*r;/计算圆周长1s=r*r*p i ;计算圆面积ss q=4*p i*r*r;计算圆球表面积s qv q=3.0/4.0*p i*r*r*r;计算圆球体积 v qv z=p i*r*r*h;计算圆柱体积v zp r i n t f (圆周长为:1=%6.2f nz,,1);p r i n t f (圆面积为:s=%6.2f n,s);p r i n t f (圆球表面积为:s q=%6.2f n ,s q);p r i n t f (圆球体积为:v=%6.2f n ,v q);p r i n t f (“圆柱体积为:v z=%6.2f n ,v z);r e t

13、 u r n 0;3-8-1#i n c l u d e i n t m ai n()i n t c l,c 2;整型定义p r i n t f (请输入两个整数c l,c 2:);s c an f (%d,%d ,&c l,&c 2);p r i n t f (按字符输出结果:n);p r i n t f (%c,%c nz,,c l,c 2);p r i n t f (按AS CII码输出结果为:n);p r i n t f (%d,%d n,/,c l,c 2);r e t u r n 0;3-8-2#i n c l u d e i n t m ai n Oc h ar c l,c 2;

14、定义字符型变量i n t i 1,i 2;定义整型变量p r i n t f (请输入两个字符c l,c 2:);s c an f (%c,%c”,&c l,&c 2);i l=c l;赋值给整型变量i 2=c 2;p r i n t f(按字符输出结果:n );p r i n t f (,z%c,%c n,z,i l,i 2);p r i n t f (按整数输出结果:n);p r i n t f (%d,%d n,c l,c 2);r e t u r n 0;3-8-3#i n c l u d e i n t m ai n O(c h ar c l,c 2;i n t i l,i 2;p

15、r i n t f (请输入两个整数 i l,i 2:);s c an f C%d,%d,&i l,&i 2);c l=i l;c 2=i 2;p r i n t f (按字符输出结果果n );p r i n t f(%c,%c n,c l,c 2);p r i n t f (按整数输出结果果n);p r i n t f (d,%d n”,c l,c 2);r e t u r n 0;3-8f t i n c l u d e i n t m ai n O(c h ar c l,c 2;p r i n t f (请输入两个字符 c l,c 2:z,);c l=g e t c h ar();c 2

16、=g e t c h ar();p r i n t f (用 p u t c h ar 语句输出结果为:);p u t c h ar (c l);p u t c h ar(c 2);p r i n t f(n);p r i n t f (用 p r i n t f 语句输出结果为为);p r i n t f (z,%c%c n,,c l,c 2);r e t u r n 0;)第 4 章选择结构程序设计【第 1 1 1 页】4-4-1S i n c l u d e 定义为字符型定义为整型将整数赋值给字符变量i n tm ai n()(i n t a,b,c;p r i n t f (请输入三个

17、整数:);s c an f (z/%d,%d,%d”,&a,&b,&c);i f (ab)i f (bc)p r i n t f(m ax=%d n,c);e l s ep r i n t f (m ax=%d n,b);e l s e i f (ac)p r i n t f(m ax=%d n ,c);e l s ep r i n t f(m ax=%d n ,a);r e t u r n 0;)4-4-2#i n c l u d e i n t m ai n O i n t a,b,c,t e m p,m ax;p r i n t f (请输入三个整数:);s c an f (%d,%d,

18、%d”,&a,&b,&c);t e m p=(ab)?a:b;/*将 a 和 b 中的大者存入t e m p 中*/m ax 二(t e m p c)?t e m p:c;/*将 a 和 b 中的大者与c比较,取最大者*/p r i n t f (三个整数的最大数是 d n ,m ax);r e t u r n 0;)4-5-2t t i n c l u d e i n c l u d e#d e f i n e M 1 000i n t m ai n O(i n t i,k;p r i n t f (请输入,个小于%d的整数i :,M);s c an f;w h i l e (i M)p r

19、 i n t f (输入的数不符合要求,请重新输入一个小于%d 的整数i:,M);s c an f (,z%d,z,&i);k=s q r t (i);p r i n t f (%d 的平方根的整数部分是:%d n,i,k);r e t u r n 0;4-5#i n c l u d e#i n c l u d e#d e f i n e M 1 000i n t m ai n()(i n t i,k;p r i n t f (请输入一个小于%d的整数i:,M);sca nf&i);i f (i M)p r i n t f (输入的数不符合要求,请重新输入一个小于%d 的整数i :,M);sc

20、a nf&i);)k=s q r t (i);p r i n t f C%d 的平方根的整数部分是:%d n ,i,k);r e t u r n 0;)4-6.t t i n c l u d e i n t m ai n()i n t x,y;p r i n t f (输入 x:);sca nf&x);i f(x l)/*x l */y =x;p r i n t f(x=%3d,y二x=%d n ,x,y);)e l s e i f(x 1 0)/*l=x=1 0*/y=3*x-l l;p r i n t f (x=%d,y=3*x T l或d n”,x,y);)r e t u r n 0;4

21、-7-1#i n c l u d e i n t m ai n()i n t x,y;p r i n t f(z,e n t e r x:);s c an f(%d,&x);y 二 T;i f(x!=O)i f(x 0)y=l;e l s ey=0;p r i n t f (/zx=%d,y=%d nz,,x,y);r e t u r n 0;)4-7-2#i n c l u d e i n t m ai n()(i n t x,y;p r i n t f (p l e as e e n t e r x:);s c an f (%d ,&x);y=0;i f(x=0)i f(x 0)y=l;e

22、 l s e y=一1;p r i n t f (x=%d,y=%d n,x,y);r e t u r n 0;)4-8f t i n c l u d e i n t m ai n()f l o at s c o r e;c h ar g r ad e;p r i n t f (请输入学生成绩:);s c an f (%f,f i s c o r e);w h i l e (s c o r e 1 00|s c o r e 0)p r i n t f (z,n 输入有误,请重输”);s c an f(f”,&s c o r e);)s w i t c h(i n t)(s c o r e/1

23、0)c as e 1 0:c as e 9:g r ad e=A;br e ak;c as e 8:g r ad e=B ;br e ak;c as e 7:g r ad e=C;br e ak;c as e 6:g r ad e=D;br e ak;c as e 5:c as e 4:c as e 3:c as e 2:c as e 1:c as e 0:g r ad e=E;)p r i n t f (成绩是%5.If,相应的等级是%c n ,s c o r e,g r ad e);r e t u r n 0;)4-9#i n c l u d e t t i n c l u d e i n

24、 t m ai n Oi n t n u m,i n d i v,t e n,h u n d r e d,t h o u s an d,t e n t h o u s an d,p l ac e;分别代表个位,十位,百位,千位,万位和位数p r i n t f (请输入一个整数(0-99999):);s c an f(%d,&n u m);i f (n u m 9999)p l ac e=5;e l s e i f (n u m 999)p l ac e=4;e l s e i f (n u m 99)p l ac e=3;e l s e i f (n u m 9)p l ac e=2;e l

25、 s e p l ac e=l;p r i n t f (位数:%d n”,p l ac e);p r i n t f (每位数字为:);t e n _t h o u s an d=n u m/1 0000;t h o u s an d=(i n t)(n u m-t e n _t h o u s an d*l 0000)/1 000;h u n d r e d=(i n t)(n u m-t e n _t h o u s an d*1 0000-t h o u s an d*1 000)/1 00;t e n=(i n t)(n u m-t e n _t h o u s an d*1 000

26、0-t h o u s an d*1 000-h u n d r e d*1 00)/1 0;i n d i v:=(i n t)(n u m-t e n t h o u s an d*1 0000-t h o u s an d*1 000-h u n d r e d*1 00-t e n*1 0);s w i t c h(p l ac e)c as e 5:p r i n t f (z,%d,%d,%d,%d,%d,z,t e n _t h o u s an d,t h o u s an d,h u n d r e d,t e n,i n d i v);p r i n t f (n反序数字为

27、:);p r i n t f (/,%d%d%d%d%d n/,,i n d i v,t e n,h u n d r e d,t h o u s an d,t e n _t h o u s an d);br e ak;c as e 4:p r i n t f(%d,%d,%d,%d,t h o u s an d,h u n d r e d,t e n,i n d i v);p r i n t f (n反序数字为:);p r i n t f Cz%d%d%d%d nz,,i n d i v,t e n,h u n d r e d,t h o u s an d);br e ak;c as e 3:

28、p r i n t f (,z%d,%d,%d,z,h u n d r e d,t e n,i n d i v);p r i n t f C n反序数字为:);p r i n t f(d%d%d n,i n d i v,t e n,h u n d r e d);br e ak;c as e 2:p r i n t f (/z%d,%d/z,t e n,i n d i v);p r i n t f (n反序数字为:);p r i n t f(d%d n,i n d i v,t e n);br e ak;c as e 1:printfindiv);p r i n t f (n反序数字为:);p r

29、 i n t f(%d n,i n d i v);br e ak;)r e t u r n 0;)4-1 0-1#i n c l u d e i n t m ai n()i n t i;d o u bl e bo n u s,bo n l,bo n 2,bo n 4,bo n 6,bo n l O;bo n l=1 00000*0.1;bo n 2=bo n l+1 00000*0.075;bo n 4=bo n 2+1 00000*0.05;bo n 6=bo n 4+1 00000*0.03;bo n l 0=bo n 6+400000*0.01 5;p r i n t f(请输入利润i:

30、);s c an f (,z%d/z,&i);i f (i=1 00000)bo n u s=i*0.1;e l s e i f (i=200000)bo n u s=bo n l+(i-1 00000)*0.075;e l s e i f (i=400000)bo n u s=bo n 2+(i-200000)*0.05;e l s e i f (i=600000)bo n u s=bo n 4+(i-400000)*0.03;e l s e i f (i=1 000000)bo n u s=bo n 6+(i-600000)*0.01 5;e l s ebo n u s=bo n l 0+

31、(i-1 000000)*0.01;p r i n t f (奖金是:%1 0.2f nz,,bo n u s);r e t u r n 0;4-10-2#include int main()(int i;double bonus,bonl,bon2,bon4,bon6,bonlO;int branch;bonl=10 0 0 0 0*0.1;bon2=bonl+10 0 0 0 0*0.0 75;bon4=bon2+2 0 0 0 0 0*0.0 5;bon6=bon4+2 0 0 0 0 0*0.0 3;bon10=bon6+40 0 0 0 0*0.0 15;14玳六请输入利润1:);s

32、canf(级d,&i);branch=i/10 0 0 0 0;if(branch10)branch=10;switch(branch)case 0:bonus=i*0.1;break;case 1:bonus=bonl+(i-10 0 0 0 0)*0.0 75;break;case 2:case 3:bonus=bon2+(i-2 0 0 0 0 0)*0.0 5;break;case 4:case 5:bonus=bon4+(i-40 0 0 0 0)*0.0 3;break;case 6:case 7:case 8:c as e 9:bo n u s=bo n 6+(i-600000)

33、*0.01 5;br e ak;c as e 1 0:bo n u s=bo n l O+(i-1 000000)*0.01;p r i n t f (奖金是%1 0.2f n,z,bo n u s);r e t u r n 0;)4-1 1t t i n c l u d e i n t m ai n()i n t t,a,b,c,d;p r i n t f (请输入四个数:);s c an f (,z%d,%d,%d,%d ,&a,&b,&c,&d);p r i n t f (z,a=%d,b=%d,c=%d,d二%d n”,a,b,c,d);i f (ab)t=a;a=b;b=t;i f

34、(ac)t=a;a=c;c=t;i f (ad)t =a;a=d;d=t;i f (bc)t=b;b=c;c=t;i f (bd)t=b;b=d;d=t;i f (c d)t=c;c二d;d=t;printf(排序结果如下:n);printf(d%d%d%d n,a,b,c,d);return 0;)4-12include int main()(int h=10;float xl=2,yl=2,x2=-2,y2=2,x3=-2,y3=-2,x4=2,y4=-2,x,y,dl,d2,d3,d4;printf(z/请输入一个点(x,y);scanf(f,%f,&x,&y);dl=(x-x4)*(x

35、-x4)+(y-y4)*(y-y4);/*求该点到各中心点距离*/d2=(x-xl)*(x-xl)+(y-yl)*(y-yl);d3=(x-x2)*(x-x2)+(y-y2)*(y-y2);d4=(x-x3)*(x-x3)+(y-y3)*(y-y3);if(dll&d2 l&d3l&d4l)h=0;/*判断该点是否在塔外*/printf(该点高度为%dn,z,h);return 0;)第5章循环结构程序设计【第140页】5-2#include ttinclude /程序中用到数学函数fa b s,应包含头文件math,n int main()i n t s i g n al,c o u n t

36、=0;/s i g n 用来表示数值的符号,c o u n t 用来统计循环次数d o u bl ep i=0.0,n=1.0,t e r m=1.0;/p i 开始代表多项式的值,最后代表兀的值,n 代表分母,t e r m 代表当前项的值w h ile(f abs (t e r m)=le-8)/检查当前项t e r m 的绝对值是否大于或等于1 0 的(-6)次方(p i=p i+t e r m;/把当前项t e r m 累加到p i 中n=n+2;n+2是下一项的分母s ig n=-s ig n;s ig n代表符号,下一项的符号与上一项符号相反t e r m=s ig n/n;/求出

37、下一项的值t e r mc ou nt+;/c ou nt 累加 1)p i=p i*4;/多项式的和 p i 乘以 4,才是 n 的近似值 p r int f Czp i=%1 0.8 f n,z,p i);/输 出 n 的近似值p r int f (/zc ou nt=%d n,z,c ou nt);/输出循环次数r e t u r n 0;)5-3#inc lu d e int m ain()int p,r,n,m,t e m p;p r int f (请输入两个正整数n,m:);s c anf (z,%d,%d,,&n,&m);if (n m)t e m p=n;n=m;m=t e m

38、 p;p=n*m;w h ile(m!=0)(r=n%m;n=m;m=r;)p r int f (它们的最大公约数为册d n,n);p r int f (它们的最小公约数为:d n,p/n);r e t u r n 0;)5-4inc lu d e int m ain()(c h ar c;int le t t e r s、。,s p ac e=O,d ig it=O,ot h e r=0;p r int f (请输入一行字符:n);w h ile(c=g e t c h ar ()!=n)if (c 二 a|c=A&c=O&c=,9)d ig it+;e ls eot h e r+;p r

39、int f (字母数:%d n空格数:d n数字数:%d n其它字符数:八。,le t t e r s,s p ac e,d ig it,ot h e r);r e t u r n 0;)5-5S inc lu d e int m ain()(int a,n,i=l,s n=0,t n=O;p r int f(a,n二:);s c anf (/z%d,%d,&a,&n);w h ile (i=n)t n二 t n+a;/*赋值后的t n为 i 个 a 组成数的值*/s n=s n+t n;/*赋值后的s n为多项式前i 项之和*/a=a*1 0;+i;)p r int f (/za+aa+aa

40、a+.二 d n,s n);r e t u r n 0;)5-6t f inc lu d e int m ain()d ou ble s=0,t=l;int n;f or (n=l;n=20;n+)(t=t*n;s=s+t;)p r int f(1!+2!+.+20!=%22.1 5 e n,s);r e t u r n 0;)5-7#inc lu d e int m ain()int nl=10 0,n2=50,n3=10;double k,sl=0,s2=0,s3=0;for(k=l;k=nl;k+)/*计算 1 到 10 0 的和*/sl=sl+k;for(k=l;k=n2;k+)/*计

41、算 1 到 50 各数的平方和*/s2=s2+k*k;for(k=l;k=n3;k+)/*计算 1 到 10 的各倒数和*/s3=s3+l/k;printf Csum=%15.6fn”,sl+s2+s3);return 0;)5-8#include int main()(int i,j,k,n;printf(z,parcissus numbers are );for(n=10 0;n 10 0 0;n+)i=n/10 0;j=n/10-i*10;k=n%10;if(n=i*i*i+j*j*j+k*k*k)printf(,z%d ,n);printf Cn);return 0;5-9-1#def

42、ine M 1000/*定义寻找范围*/#include int main()(int kl,k2,k3,k4,k5,k6,k7,k8,k9,klO;int i,a,n,s;for(a=2;a=M;a+)/*a是2T000之间的整数,检查它是否完数*/n=0;/*n用来累计a的因子的个数*/s=a;/*s用来存放尚未求出的因子之和,开始时等于a*/for(i=l;il)p r int f (z z%d,%dz,,k l,k 2);/*nl 表示 a 至少有 2 个因子*/if (n2)p r int f k 3);/*n2表示至少有3 个因子,故应再输出一个因子*/if (n3)p r int

43、 f (,d ,k 4);因 子*/if (n4)p r int f (,%d”,k 5);if (n5)p r int f(,%d ,k 6);if(n6)printf(,z,%d,k7);if(n7)printf(,%d,k8);if(n8)printf(,%d,k9);if(n9)printf%d,z,klO);printf(n);)return 0;)5-9-2#include int main()int m,s,i;for(m=2;m1000;m+)s=0;for(i=l;im;i+)if(m%i)=0)s=s+i;if(s=m)printf(z,%d,its factors are

44、 ,m);for(i=l;i3表示至少有4个因子,故应再输出一个/*以下类似*/#inc lu d eint m ain()(int i,n=20;d ou ble a=2,b=l,s=0,t;f or (i=l;i=n;i+)(s=s+a/b;t=a,a=a+b,b=t;)p r int f (s u m二 机6.1 0 f n,s);r e t u r n 0;)5-1 1#inc lu d e int m ain()d ou ble s n=1 0 0,h n=s n/2;int n;f or (n=2;n=1 0;n+)(s n=s n+2*h n;/*第 n 次落地时共经过的米数*/

45、h n=h n/2;/*第 n 次反跳高度*/)p r int f (第1 0 次落地时共经过%f 米 n,s n);p r int f (第 1 0 次反弹%f 米 n,h n);r e t u r n 0;)5-1 2#inc lu d e int m ain()(int d ay,xl,x2;d ay=9;x2=l;w h ile (d ay 0)xl=(x2+l)*2;/*第 1 天的桃子数是第2 天桃子数加1 后的2 倍.*/x2=xl;d ay-;)p r int f (t ot al二%d n,xl);r e t u r n 0;5-13#include#include int

46、mainO(float a,xO,xl;printf(enter a positive number:);scanf&a);x0=a/2;xl=(x0+a/x0)/2;doxO=xl;xl=(x0+a/x0)/2;while(fabs(xO-xl)=le-5);printf(The square root of%5.2f is%8.5fn,z,a,xl);return 0;)5-14#include ftinclude int mainOdouble xl,xO,f,f l;xl=l.5;doxO=xl;f=(2*x0-4)*x0+3)*x0-6;fl=(6*x0-8)*x0+3;xl=xO-

47、f/fl;while(fabs(xl-xO)=le-5);printf(,zThe root of equation is%5.2fn,z,xl);return 0;)5-15#include#include int main()float xO,xl,x2,fxO,fxl,fx2;doprintf(enter xl&x2:);scanf%f,z,&xl,&x2);f xl=xl*(2*xl-4)*xl+3)-6;fx2=x2*(2*x2-4)*x2+3)-6;while(fxl*fx20);dox0=(xl+x2)/2;fx0=x0*(2*x0-4)*x0+3)-6;if(fx0*fxl)=

48、le-5);printf(x=%6.2fn,xO);return 0;5-1 6#inc lu d e int m ainOint i,j,k;f or (i=0;i=3;i+)f or (j=0;j =2-i;j+)p r int f();f or (k=0;k=2*i;k+)p r int f(*);p r int f (n);)f or (i=0;i=2;i+)f or (j=0;j =i;j+)p r int f();f or (k=0;k =4-2*i;k+)p r int f(*);p r int f C nz,);r e t u r n 0;)5-1 7#inc lu d e i

49、nt m ainO(c h ar i,j,k;/*是 a 的对手;j 是 b 的对手;k 是 c 的对手*/f or (i=x;i 二 z ;i+)f or (j=,x;j -z;j+)if =j)f or (k=,x ;k =z ;k+)if (i!=k&j!=k)if (i!=x&k!=x&k!=z)p r int f (Z/A一%c nB-%c nC-%c n,i,j,k);r e t u r n 0;)第 6章利用数组处理批量数据【第 1 6 8 页】6-1#inc lu d e t t inc lu d e int m ain()int i,j,n,a 1 0 1 ;f or (i=

50、l;i=1 0 0;i+)a i=i;a l=0;f or (i=2;i s q r t(1 0 0);i+)f or (j=i+l;j =1 0 0;j+)if(a i!=0&a j !=0)if (a j%a i=0)a j =0;)p r int f (n);f or (i=2,n=0;i=1 0 0;i+)if(a i!=0)printf(%5d,a i);n+;)if(n=10)printf(n);n=0;)p rin tf(n);return 0;6-2#include int main()int i,j,min,temp,a ll;p rin tf(,zenter data:n)

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

当前位置:首页 > 教育专区 > 教案示例

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

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com