C/C++经典程序训练2---斐波那契数列

#include <stdio.h>
#include <math.h>

int fib(int n);
int main()
{
    int n;
    scanf("%d", &n);
    int x = fib(n);
    printf("%d\n", x);
    return 0
    ;
}
int fib(int n)
{
    int x;
    if((n==1)||(n==2))
    {
        x = 1;
    }
    else
    {
        x = fib(n-1) + fib(n-2);
    }
    return x;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-04-25
猜你喜欢
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案