Home > Back-end >  The Fibonacci sequence N items, ask for help!
The Fibonacci sequence N items, ask for help!

Time:10-28

Enter a different value no problem input 1 or 2, 133,,,
#include
Int main (void)
{
Int N, f1, f2, I, A;
F1=1;
F2=1;
The scanf (" % d ", & amp; N);
If (N
=2)Printf (" 1 ");
If (N> 2)
{
For (I=3; i<=N; I++)
{
A=f1 + f2;
F1=f2;
F2=A;
}
}
Printf (" % d ", A % 2000000003);
return 0;
}

CodePudding user response:

 # include 

Int main (void)
{
Int N, f1, f2, I, A;
F1=1;
F2=1;
The scanf (" % d ", & amp; N);
If (N<=2) {
Printf (" 1 ");
return 0;
}
//if (N> 2)
//{
For (I=3; i<=N; I++)
{
A=f1 + f2;
F1=f2;
F2=A;
}
//}
Printf (" % d \ n ", A % 2000000003);

return 0;
}

For your reference ~

Because there is no initialization, A type 1 or 2, executes the last printf statements, because is A random value, so may appear 133;

CodePudding user response:

N<=2, A no assignment, so A is not affirmatory, either in print (" 1 ") after the return, or print (" 1 ") to A=1
  • Related