斐波那契数列(Fibonacci sequence),又称黄金分割数列,因数学家莱昂纳多·斐波那契(Leonardo Fibonacci)引入
通项公式如上
递归表达式
def fib(n):
fib(n) =
fib(n - 1) +fib(n - 2)
print('\n 最终结果为 %d'%(fib(n)))
代码如下
#include<stdio.h>
#include<math.h>
int main(void)
{
int n;
float b, c, d;
int fib;
printf("input n:");
scanf_s("%d", &n);
b = pow(5, 0.5);
c = (1 + b) / 2, d = (1 - b) / 2;
fib = 1/b * (pow(c, n) - pow(d, n));
printf("fib(%d)=%d", n, fib);
return 0;
}
标签:fib,数列,int,pow,斐波,那契
From: https://www.cnblogs.com/lin-zhi-yuan/p/16773526.html