Description

 

编写递归函数,该函数可以求出裴波那契数列的任意一项

Input

输入一个正整数

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Output

输出数列中该项的值

Sample Input

3

Sample Output

2  

#include <stdio.h>
#include <stdlib.h>

int f(int a)
{
  int r;
  if(a<=2)
    return 1;
  return r=f(a-1)+f(a-2);
}
int main()
{
  int n;
  int m;
  scanf("%d",&n);
  m=f(n);
  printf("%d\n",m);
  return 0;
}

 

 
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄