Fibonacci数列的递归函数实现——4-05.c 256 B

12345678910111213141516
  1. #include <stdio.h>
  2. int fibonacci(int n) {
  3. if (n == 0 || n == 1) {
  4. return 1;
  5. } else {
  6. return fibonacci(n - 1) + fibonacci(n - 2);
  7. }
  8. }
  9. int main() {
  10. int n;
  11. scanf("%d", &n);
  12. printf("%d", fibonacci(n));
  13. return 0;
  14. }