1176 Fibonacci Array

Niloy Sarker
By -
0
URI Online Judge | 1176

Fibonacci Array

Write a program that reads a number and print the Fibonacci number corresponding to this read number. Remember that the first elements of the Fibonacci series are 0 and 1 and each next term is the sum of the two preceding it. All the Fibonacci numbers calculated in this program must fit in a unsigned 64 bits number.

Input

The first line of the input contains a single integer T, indicating the number of test cases. Each test case contains a single integer N (0 ≤ N ≤ 60), corresponding to the N-th term of the Fibonacci series.

Output

For each test case in the input, print the message "Fib(N) = X", where X is the N-th term of the Fibonacci series.
Input SampleOutput Sample
3
0
4
2
Fib(0) = 0
Fib(4) = 3
Fib(2) = 1
Solution :

#include<stdio.h>
int main()
{
    int i,n,m;
    long long int N[61];
    N[0]=0;
    N[1]=1;
    for(i = 2;i < 61;i++){
        N[i]=N[i-1]+N[i-2];
    }
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%d",&m);
        printf("Fib(%d) = %lld\n",m,N[m]);
    }
    return 0;
}
Tags:

Post a Comment

0Comments

Post a Comment (0)