递归法求斐波那契数列

 #include <stdlib.h>
 #include <stdio.h>
 int fib(int n)
 {
     while (n==1||n==2)
     return 1;
     return fib(n-1)+fib(n-2);
     }
  int main ()
  {
     int n;
     scanf("%d",&n);
     printf("%d\n,fib(n));
     return 0;
     }

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44840046/article/details/89431386