Home > Back-end >  C the Fibonacci sequence, fails to solve
C the Fibonacci sequence, fails to solve

Time:10-25

As shown in figure, there is no error, only to generate failure, this is how the

The code
# include & lt; stdio.h>
Int fun (int n);
The main ()
{
Int I, n=0;
The scanf (" % d ", & amp; n);
for (i=0; iPrintf (" % d ", fun (I));
}
Int fun (int n)
{
If (n==0)
return 0;
Else if (n==1)
return 1;
The else
return fun(n-1)+fun(n-2);
}

CodePudding user response:

Main function with integer or empty type operation is int main (), or void main ()

CodePudding user response:

The
reference program mode response: 1/f,
main function using integer arithmetic or empty type is int main (), or void main ()

Ah yes, really
Thank you very much!

CodePudding user response:

You can use the vs2019 IDE

CodePudding user response:

It can prompt you where is wrong

CodePudding user response:

reference program mode 4 floor response:
it can prompt you where wrong

Wow
Oh really thank you!

CodePudding user response:

Another don't know the code structure of PE teacher to teach
Int main () {
.
return 0;
}
Is the structure of the standard

In addition, the method to realize this recursive, n not big, or very slow even stack overflow
More suitable for using recursive method to solve the
Int fun (int n) {
Int f1=0;
int f2=1;
Int f=0;
For (int j=2; j<=n; J++) {
F=f2 + f1;
F1=f2;
F2=f;
}
Return the f;
};

CodePudding user response:

Fun
reference 6 floor response:
another don't know the code structure of PE teacher to teach
Int main () {
.
return 0;
}
Is the structure of the standard

In addition, the method to realize this recursive, n not big, or very slow even stack overflow
More suitable for using recursive method to solve the
Int fun (int n) {
Int f1=0;
int f2=1;
Int f=0;
For (int j=2; j<=n; J++) {
F=f2 + f1;
F1=f2;
F2=f;
}
Return the f;
};


Really, thank you thank you!
  • Related