Write a program that reads an integer N
and print then prints the Nth value
in the Fibonacci sequence.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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 <= 90),
corresponding to the N-th
term of the Fibonacci sequence.
For each test case in the input,
print the case number
print the message "Fib(N) = X",
where X is the N-th term of the Fibonacci series.
Special Requirement
Your program must use an array
to store the first 91 values in the fibonacci sequence.
Desired output:
1 2 3 4 5 6 7 8 9 10
Input Sample
3
0
4
2
Output Sample:
Case 1: Fib(0) = 0
Case 2: Fib(4) = 3
Case 3: Fib(2) = 1
Now my code is running correctly,
but when i sample input numbers are large the output is incorrect.
1 2 3 4 5
example
my output:
case 1: Fib(52) = -1408458269
desired output:
case 1: Fib(52) = 32951280099
I believe that this part of my code is not correct:
In standard C++, the size of an array on the stack must be known at compile-time, so it must be a compile-time constant (like you do for x at line 12). You can't declare the size using a variable like n that is only known at run-time.
Presumably, you are using a compiler that allows this as an extension, but you really should be learning to code standard C++, not some proprietry extension.