#include
using namespace std;
int fibonacci(int n){
int fibo;
static int temp;
if (n == 1 || n == 2)
fibo = 1;
else{
fibo = fibonacci(n-1) + fibonacci(n-2);
if (temp < fibo){
cout << " " << fibo;
temp = fibo;
}
}
return fibo;
}
int main(){
int n, fibon;
cout << "Please input a positive integer:";
cin >> n;
cout << "The " << n << " number of fibonacci is:\n [ 1 1";
fibon = fibonacci(n);
cout << " ]\n " << fibon << endl;
system("pause");
}
应该是这样,按公式(f(n)=f(n-1)+f(n-2)).