再帰③|フィボナッチ数列
#include <bits/stdc++.h> using namespace std; //再帰 - フィボナッチ int fib( int N ) { if( N == 0 )//基底部 { return 0; } else if( N == 1 )//基底部 { return 1; } else //再帰部 { return ( fib( N - 2 ) + fib( N - 1 ) ); } } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; cout << fib( N ) << endl; return 0; }
階乗より理解が楽だった...