Topic: The Fibonacci number is defined as: F (0) =0,f (1) =1,f (n) =f (n-1) +f (n-2) (N>1 and N is an integer)
If you write the Phillips series, it should be:
0 1 1 2 3 5 8 13 21 34 ...
If the 6th item is to be asked, it shall be 8.
Find the nth Xiangfi number.
Input Description: The input data contains no more than 50 positive integer n (0<=n<=46).
Output Description: For each n, calculate its nth Xiangfi number, each result should be a separate row.
Topic Analysis: First of the No. 0 to the 46th Fibonacci number to find out, put in an array, and then directly to the table can be, so no time out.
Reference code:
Copy Code code as follows:
#include <iostream>
#include <fstream>
#include <cmath>
using namespace Std;
int main (int argc,char * argv[])
{
int a[47];
a[0]=0;
A[1]=1;
for (int i=2;i<=46;i++)
{
A[I]=A[I-1]+A[I-2];
}
int n;
while (Cin>>n)
{
cout<<a[n]<<endl;
}
System ("pause");
return 0;
}
Effect as shown: