天天看點

遞歸函數求斐波那契數列

#include <iostream>

using namespace std;

int fib(int n);

int main ()

{

    int m;

    cin>>m;

    int s;

    s=fib(m);

    cout<<s;

    return 0;

}

int fib(int n)

{

    if (n==1)

        return 0;

    if (n==2)

        return 1;

    else return fib(n-1)+fib(n-2);