《C语言程序设计》课后习题答案谭浩强 下载本文

for (n=2;n<=10;n++) {

sn=sn+2*hn; /*第n次落地时共经过的米数*/ hn=hn/2; /*第n次反跳高度*/ }

printf(\第10次落地时共经过%f米\\n\printf(\第10次反弹%f米\\n\return 0; } 5-12

#include int main() {

int day,x1,x2; day=9; x2=1; while(day>0)

{x1=(x2+1)*2; /*第1天的桃子数是第2天桃子数加1后的2倍.*/ x2=x1; day--; }

printf(\return 0; } 5-13

#include #include int main() {

float a,x0,x1;

printf(\scanf(\x0=a/2; x1=(x0+a/x0)/2; do {x0=x1; x1=(x0+a/x0)/2;

}while(fabs(x0-x1)>=1e-5);

printf(\return 0; } 5-14

#include #include int main() {double x1,x0,f,f1; x1=1.5; do {x0=x1;

f=((2*x0-4)*x0+3)*x0-6;

f1=(6*x0-8)*x0+3; x1=x0-f/f1;

}while(fabs(x1-x0)>=1e-5);

printf(\return 0; } 5-15

#include #include int main()

{float x0,x1,x2,fx0,fx1,fx2; do

{printf(\scanf(\fx1=x1*((2*x1-4)*x1+3)-6; fx2=x2*((2*x2-4)*x2+3)-6; }while(fx1*fx2>0); do

{x0=(x1+x2)/2;

fx0=x0*((2*x0-4)*x0+3)-6; if ((fx0*fx1)<0) {x2=x0; fx2=fx0; } else

{x1=x0; fx1=fx0; }

}while(fabs (fx0)>=1e-5); printf(\return 0; } 5-16

#include int main() {int i,j,k; for (i=0;i<=3;i++) {for (j=0;j<=2-i;j++) printf(\for (k=0;k<=2*i;k++) printf(\printf(\}

for (i=0;i<=2;i++) {for (j=0;j<=i;j++) printf(\

for (k=0;k<=4-2*i;k++) printf(\printf(\}