#include <stdio.h>
long fabonacci(int n)
{
long result;
long pre_result;
long pre_pre_result;
result = pre_result = 1;
while (n > 2)
{
n -= 1;
pre_pre_result = pre_result;
pre_result = result;
result = pre_result + pre_pre_result;
}
return result;
}
int main()
{
printf("%lu\n", fabonacci(21));
}
用迭代法计算斐波那契数
最新推荐文章于 2021-11-26 21:05:27 发布