📄 example 6_3.cpp
字号:
//Chapter 6: Fibonacci Number
#include <iostream>
using namespace std;
int rFibNum(int a, int b, int n);
int main()
{
int firstFibNum;
int secondFibNum;
int nth;
cout<<"Enter the first Fibonacci number: ";
cin>>firstFibNum;
cout<<endl;
cout<<"Enter the second Fibonacci number: ";
cin>>secondFibNum;
cout<<endl;
cout<<"Enter the position of the desired Fibonacci number: ";
cin>>nth;
cout<<endl;
cout<<"The Fibonacci number at position "<<nth<<" is: "
<< rFibNum(firstFibNum, secondFibNum, nth)<<endl;
return 0;
}
int rFibNum(int a, int b, int n)
{
if(n == 1)
return a;
else if(n == 2)
return b;
else
return rFibNum(a, b, n - 1) + rFibNum(a, b, n - 2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -