C语言经典例题简单算法

来源:互联网 发布:js合并数组中的集合 编辑:程序博客网 时间:2024/05/22 06:20

又一个经典C语言例题,摘自C语言网。

题目:

一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?
1.程序分析:
见下面注释
2.程序源代码:
main()
{
float sn=100.0,hn=sn/2;
int n;
for(n=2;n<=10;n++)
{
sn=sn+2*hn;/*第n次落地时共经过的米数*/
hn=hn/2; /*第n次反跳高度*/
}
printf( “C语言研究中心 www.dotcpp.com\n” );
printf(“the total of road is %f\n”,sn);
printf(“the tenth is %f meter\n”,hn);

}

以上就是解题过程了。

0 0