/*
*copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:hellow.cpp
*作者:田甜
*完成日期:2016年3月24日
*版本号:v1.0
*
*问题描述:编制递归函数fib(int n)返回第n个Fibnacci数,以此输出Fibnacci序列的第20个数。
*输入描述:无
*程序输出:第20个Fibnacci数
*/
问题及代码:
#include<iostream>
using namespace std;
int fib(int n);
int main()
{
cout<<fib(20)<<endl;
return 0;
}
int fib(int n)
{
if(n==1)
return 0;
if(n==2)
return 1;
else
return fib(n-1)+fib(n-2);
}
运行结果:
知识点总结:
递归
学习心得: