递归求斐波那契而数列__2019.03.18

#include <iostream>
using namespace std;

int fun(int n)
{
	if (n == 3||n==2)
	{
		return 1;
	}
	else if (n > 3)
	{
		return fun(n - 1) + fun(n - 2);
	}
}

int main()
{
	int n = 0;
	cin >> n;
	int i = 4;
	cout << "0" << " " << "1" << " " << "1" << " ";
	while (i>3&&i<=n)
	{
		cout << fun(i++) << " ";
	}
	cout << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_40316053/article/details/88632444
今日推荐