U E D R , A S I H C RSS

피보나치/곽세환

~cpp 
#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);
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:27
Processing time 0.0114 sec