用C語言證明費波拉契數列中Fn/Fn+1等於黃金分割。要求有輸入輸出
int foo(int n)
{
if (n == 1 || n == 2)
return 1;
return foo(n - 1) + foo(n - 2);
}
int main()
{
for (int i = 1; i < 20; i++)
{
cout << foo(i) / (double)foo(i + 1) << endl;
}
}
1
0.5
0.666667
0.6
0.625
0.615385
0.619048
0.617647
0.618182
0.617978
0.618056
0.618026
0.618037
0.618033
0.618034
0.618034
0.618034
0.618034
0.618034