U E D R , A S I H C RSS

피보나치/장창재 (rev. 1.1)

피보나치/장창재

#include <iostream.h>

int pi(int a);

int main()
{
	int a,result;

	while (cin >> a)
	{
	
	result = pi(a);

	cout << a << "번째 값은 = " << result << endl;
	}
	return 0;
}

int pi(int a)
{
	if (a == 1)
		return 1;
	
	if (a == 2)
		return 2;

	else
		return pi(a-1) + pi(a-2);
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:28
Processing time 0.0582 sec