⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3_14.cpp

📁 用递归的方法编写函数求Fibonacci级数的源程序
💻 CPP
字号:
// 3_14.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int fib(int n);

int main(int argc, char* argv[])
{
	int n;
	int answer;
	cout<<"Enter number:";
	cin>>n;
	cout<<endl;
	answer=fib(n);
	cout<<answer<<"is the"<<n<<"th Fibonacci number"<<endl;
	return 0;
}

int fib(int n)
{
	cout<<"Processing fib("<<n<<")";
	if(n<3)
	{
		cout<<"Return 1!"<<endl;
		return(1);
	}
	else
	{
		cout<<"Call fib("<<n-2<<")and fib("<<n-1<<")"<<endl;
		return(fib(n-2)+fib(n-1));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -