Time Limit: 3 Sec Memory Limit: 64 MB
Submit: 426 Solved: 260
Title Description
... infinite series 1,1,2,3,5,8,13,21,34,55 called Fibonacci series, which can be defined recursively as
F (n) = 1 ......... .. (n = 1 = 2 or n)
F. (n) = F. (. 1-n) + F. (n-2) ..... (n> 2)
is now ask you to seek the n-th Fibonacci contract number. (The first one, the second all 1)
Entry
The first row is an integer of m (m <5) m represents a total data set of test data for each test only one line, and only an integer number n (n <20)
Export
For each input n, the n-th Fibonacci number
Sample input
3 1 3 5
Sample Output
1 2 5
#include<stdio.h>
int Fib(int n){
if (n <= 2)
return 1;
else
return Fib(n - 2) + Fib(n - 1);
}
int main(){
int i;
scanf("%d",&i);
while(i--){
int n;
scanf("%d",&n);
int m = Fib(n);
printf("%d\n",m);
}
return 0;
}