Fibonacci time limit: 3000 MS | memory limit: 65535 kb difficulty: 1
-
Description
-
The infinite series, 21, 34, 55... is called the Fibonacci series, which can be recursively defined
F (n) = 1 ...... (n = 1 or N = 2)
F (n) = f (n-1) + f (n-2)... (n> 2)
I want you to calculate the nth Number of fepona. (1st and the second are both 1)
-
Input
-
The first row is an integer m (M <5), indicating a total of M groups of test data.
Each test data has only one row and only one integer n (n <20)
-
Output
-
Input n to each group, and output the nth Number of ononacci
-
Sample Input
-
3135
-
Sample output
-
125
# Include <stdio. h>
Int main ()
{
Int A [10000], M, N, I;
A [0] = 1;
A [1] = 1;
Scanf ("% d", & M );
While (M --)
{
Scanf ("% d", & N );
For (I = 2; I <n; I ++)
{
A [I] = A [I-1] + A [I-2];
}
Printf ("% d \ n", a [n-1]);
}
Return 0;
}
************************************
# Include <stdio. h>
Int main ()
{Int m, n, I;
Int A [20] = {1, 1, 2, 3 };
Scanf ("% d", & M );
While (M --)
{
Scanf ("% d", & N );
For (I = 2; I <n; I ++) // for (I = 2; I <= N; I ++)
{
A [I] = A [I-1] + A [I-2];
}
Printf ("% d \ n", a [n-1]);
}
}
**************************************** **
# Include <iostream>
Using namespace STD;
Int main ()
{
Int I, a [20], M, T;
A [1] = 1; A [2] = 1;
For (I = 3; I <= 20; I ++) A [I] = A [I-2] + A [I-1]; // calculate the first 20
Cin> m;
While (M --)
{
Cin> T;
Cout <A [T] <Endl;
}
// While (1 );
Return 0;
}