mark 一下,这个题自己的做法似乎有问题, 想使用递归,结构反而弄麻烦了. ⊙﹏⊙b汗
有空再整理吧. 1/ 幂 这种形式猛一下遇到,倒不知道怎么处理了,惭愧....
/**********************************************************************************************************
* Function : test
* Create Date : 2014/03/18
* Author : NTSK13
* Email : beijiwei@qq.com
* Copyright : 欢迎大家和我一起交流学习,转载请保持源文件的完整性。
任何单位和个人不经本人允许不得用于商业用途
转载请注明 转自 http://blog.youkuaiyun.com/beijiwei
* Version : V0.1
* date : 2014/03/18
* history : V0.1
***********************************************************************************************************
经典c程序(0012)
题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在
第10次落地时,共经过多少米?第10次反弹多高?
**********************************************************************************************************/
#include<stdio.h>
#define MY_FUNC 1
#if MY_FUNC
double get_path_longth(int m);
double get_th_high(int m,double start_high);
int main()
{
int i=0,start_high=100;
printf("The tenth highth is %f \n",get_path_longth(10) );
printf("The tenth highth is %f \n",get_th_high(10,100.0) );
return 0;
}
double get_path_longth(int m)
{
double start_high=100.0;
double m_high=1.0;
m_high=get_th_high(m,start_high);
if(m==1)
return start_high*3/2;
return get_path_longth(m-1)+m_high*3/2;
}
double get_th_high(int m,double start_high)
{
int i=0;
for(i=0;i<m;i++)
{
start_high=start_high/2;
}
return start_high;
}
// refer answer
#else
void 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("the total of road is %f\n",sn);
printf("the tenth is %f meter\n",hn);
}
#endif