经典c程序(0012)---落球问题

本文探讨了使用递归解决数学问题的方法,具体案例为计算一个自由落体球在特定次数反弹后所经过的距离与最终反弹的高度。通过实例解析,展示了如何将实际问题抽象为递归函数,并进行代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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          


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值