0
Follow
0
View

Why does this recursive function report an error?

cxs_2011 注册会员
2023-02-26 19:14
< div class = "md_content_show e397 data - v - 3967" = "" >

thank you brother, hurry upstairs to adopt to the upstairs

daiyanan6073 注册会员
2023-02-26 19:14

main

dy198528 注册会员
2023-02-26 19:14
< div class = "md_content_show e397 data - v - 3967" = "" >

hope to adopt

dbwjik 注册会员
2023-02-26 19:14
< div class = "md_content_show e397 data - v - 3967" = "" >

hope to adopt

RTY1115 注册会员
2023-02-26 19:14

Part of this answer references GPT, GPT_Pro to solve the problem better.
This error occurs when compiling Fibonacci and causes the program to fail to compile. The possible cause is:

  1. In line 9, the %d in the printf formatting string does not match the variable t and should be changed to printf("%d", t); Fibonacci(int n)
  2. Extra space after int in line 11 should be changed to int Fibonacci(int n)
  3. Extra space after int in line 14 should be changed to int t;
  4. The t in line 17 should be changed to tt, i.e. return tt;

The correct code is as follows:

#include 
 
int Fibonacci(int);
 
int main() {
    int t;
    scanf("%d", &t);
    t = Fibonacci(t);
    printf("%d", t);
    return 0;
}
 
int Fibonacci(int n) {
    int tt;
    if (n == 0) tt = 0;
    else if (n == 1) tt = 1;
    else if (n >= 2) tt = Fibonacci(n-1) + Fibonacci(n-2);
    return tt;
}

If the answer is helpful, please accept it.

doublewood21 注册会员
2023-02-26 19:14

main error, you have mian

About the Author

Question Info

Publish Time
2023-02-26 19:14
Update Time
2023-02-26 19:14