首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

斐波纳契怎样用自定义函数的迭代法编写?多谢

2012-03-23 
斐波纳契怎样用自定义函数的迭代法编写?谢谢斐波纳契怎样用自定义函数的迭代法编写?谢谢在网上搜过,搜不着

斐波纳契怎样用自定义函数的迭代法编写?谢谢
斐波纳契怎样用自定义函数的迭代法编写?谢谢
在网上搜过,搜不着......

[解决办法]
两种算法,第一个是递归,第二个是迭代
//(1)
int f(int n)//n> =0
{
if(n <2)
return n;
else
return f(n-2)+f(n-1);
}
//(2)
int f(int a,int b,int max)
{
if(max==0)
return b;
else
return f(a+b,a,max-1);
}
int f1(int n)
{
return f(1,0,n);
}

[解决办法]
while(1)
{
c=a+b;
a=b;
b=c;
}

热点排行