トップ 差分 一覧 Farm ソース 検索 ヘルプ PDF RSS ログイン

fb1.cpp

// フィボナッチ数列(再帰版)

#include <iostream>

using namespace std;

int fb(int n)
{
    if(n==0){
		return 0;
    }else if(n==1){
		return 1;
    }
	return( fb(n-1)+fb(n-2) );
}

int main()
{
    for(int i=0; i<20; i++){
	    cout << "fb(" << i << ")=" << fb(i) <<endl;
    }
    return 0;
}