Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

피보나치/곽세환

From ZeroWiki
#include <iostream>
using namespace std;

int f(int, int, int);

int main()
{
	int n;
	cout << "몇번째 수? : ";
	cin >> n;
	
	if (n == 1)
		cout << 1;
	else
		cout << f(1, 1, n-1);
	cout << endl;

	return 0;
}

int f(int a, int b, int n)
{
	if (n == 1)
		return a + b;
	else
		return f(b, a+b, n-1);
}

곽세환