一个算法题: 1、1、2、3、5、8、13、21、34 求第30位数是多少
/// <summary>
/// 一列数的规则如下: 1、1、2、3、5、8、13、21、34 求第30位数是多少, 用递归算法实现。(C#语言)
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public int GetNumberAtPos(int pos)
{
if(pos==0||pos==1)
{
return 1;
}
int res = GetNumberAtPos(pos - 1) + GetNumberAtPos(pos - 2);
return res;
}
================================================================================
这个题是已解了,我想问的是 怎么看“1、1、2、3、5、8、13、21、34 ”这列数字而推算出来的 GetNumberAtPos(pos - 1) + GetNumberAtPos(pos - 2);这个规则公式的?
1+1=2
1+2=3
2+3=5
。。。。
[解决办法]