Home > Back-end >  Hope leaders can be under the guidance of how to change the Fibonacci Numbers determine the code to
Hope leaders can be under the guidance of how to change the Fibonacci Numbers determine the code to

Time:05-11

Determine whether an integer as Fibonacci Numbers (calculated on the basis of high precision, multiple data input, until the end-of-file,
# include
Int fab (int n)
{
If (n==1)
return 1;
If (n==2)
return 1;
If (n> 2)
Return fab (n - 1) + fab (n - 2);
}
Int isfab (int m)
{
int result=0;
for(int i=0; Overall (I) & lt; m; I++)
{
If (fab (I + 1)==m)
{
Result=1;
break;
}
The else
Result=0;

}
return result;
}
Int main ()
{
int n;
While (1)
{
The scanf (" % d ", & amp; n);
If (isfab (n)==1)
Printf (" yes \ n ");
The else
Printf (" \ n ");
}
return 0;
}

CodePudding user response:

reply: refer to the original poster then China
judge whether an integer for Fibonacci Numbers (calculated on the basis of high precision, multiple data input, until the end-of-file,
# include
Int fab (int n)
{
If (n==1)
return 1;
If (n==2)
return 1;
If (n> 2)
Return fab (n - 1) + fab (n - 2);
}
Int isfab (int m)
{
int result=0;
for(int i=0; Overall (I) & lt; m; I++)
{
If (fab (I + 1)==m)
{
Result=1;
break;
}
The else
Result=0;

}
return result;
}
Int main ()
{
int n;
While (1)
{
The scanf (" % d ", & amp; n);
If (isfab (n)==1)
Printf (" yes \ n ");
The else
Printf (" \ n ");
}
return 0;
}

Mainly committed to the CG shown on the platform running time is too long

CodePudding user response:

Reference:
 # include 
Int fab (int n)
{
If (n==1)
return 1;
If (n==2)
return 1;
If (n> 2)
Return fab (n - 1) + fab (n - 2);
}
Int isfab (int m)
{
int result=0;
for(int i=0; Overall (I) & lt; m; I++)
{
If (fab (I + 1)==m)
{
Result=1;
break;
}
The else
Result=0;

}
return result;
}

Int main ()
{
int n;
While (1)
{
If (the scanf (" % d ", & amp; N)==EOF) break;
If (isfab (n)==1)
Printf (" yes \ n ");
The else
Printf (" \ n ");
}

return 0;
}

CodePudding user response:

refer to the second floor QZJHJXJ response:
for reference:
 # include 
Int fab (int n)
{
If (n==1)
return 1;
If (n==2)
return 1;
If (n> 2)
Return fab (n - 1) + fab (n - 2);
}
Int isfab (int m)
{
int result=0;
for(int i=0; Overall (I) & lt; m; I++)
{
If (fab (I + 1)==m)
{
Result=1;
break;
}
The else
Result=0;

}
return result;
}

Int main ()
{
int n;
While (1)
{
If (the scanf (" % d ", & amp; N)==EOF) break;
If (isfab (n)==1)
Printf (" yes \ n ");
The else
Printf (" \ n ");
}

return 0;
}

Bosses, this code is submitted to the CG platforms or show run time is too long!

CodePudding user response:

Try to change this:
 # include 
Int fab (int n)
{
If (n==1)
return 1;
If (n==2)
return 1;
If (n> 2)
Return fab (n - 1) + fab (n - 2);
}
Int isfab (int m)
{
int result=0;
for(int i=0; Overall (I) & lt; m; I++)
{
If (fab (I + 1)==m)
{
Result=1;
break;
}

}
return result;
}

Int main ()
{
int n;
While (the scanf (" % d ", & amp; N)!=(EOF)
{
If (isfab (n)==1)
Printf (" yes \ n ");
The else
Printf (" \ n ");
}

return 0;
}

CodePudding user response:

reference 4 floor QZJHJXJ response:
to try like this:
 # include 
Int fab (int n)
{
If (n==1)
return 1;
If (n==2)
return 1;
If (n> 2)
Return fab (n - 1) + fab (n - 2);
}
Int isfab (int m)
{
int result=0;
for(int i=0; Overall (I) & lt; m; I++)
{
If (fab (I + 1)==m)
{
Result=1;
break;
}

}
return result;
}

Int main ()
{
int n;
While (the scanf (" % d ", & amp; N)!=(EOF)
{
If (isfab (n)==1)
Printf (" yes \ n ");
The else
Printf (" \ n ");
}

return 0;
}

Bosses, or running a long time

CodePudding user response:

Try again:
 # include 
Int fab (int n)
{
If (n==1 | | n==2) return 1;
The else return fab (n - 1) + fab (n - 2);
}

Int main ()
{
Int n, I;
While (the scanf (" % d ", & amp; N)!=(EOF)
{
For (I=3; Overall (I) & lt; n; i++);
If (n==1 | | n==2 | | fab (I)==n)
Printf (" yes \ n ");
The else
Printf (" \ n ");
}

return 0;
}
  • Related