C/C++程序开发(01):斐波那契数列(不使用递归的快速算法)

 

void fabnacii(int n, int& fn)

{
if (n == 1)
{
fn = 1;
}
else if (n == 2)
{
fn = 1;
}
else if (n > 2)
{
int* Fabnacci = new int[n];
Fabnacci[0] = 1;
Fabnacci[1] = 1;
for (int i = 2; i < n; i++)
{
Fabnacci[i] = Fabnacci[i - 1] + Fabnacci[i - 2];
}
fn = Fabnacci[n - 1];
delete(Fabnacci);
}
}

你可能感兴趣的:(C/C++语言)