I had ensured that the Fibonacci numbers can be up to 2000 digits long.
BTW, here is the updated code.
[cpp]#include <stdio.h>
int main() {
const int billion = 1000000000;
int fact[5001][200], index, start;
int i, j;
for (i = 0; i <= 5000; i++)
for (j = 0; j < 200; j++)
fact[j] = 0;
fact[0][199] = 0;
fact[1][199] = 1;
for (i = 2; i <= 5000; i++)
for (j = 199; j > 0; j++) {
if (fact[j] == 0)
break;
fact[j] = fact[j] + fact[j];
fact[j - 1] = fact[j] / billion;
fact[j] %= billion;
}
while (scanf("%d", &index) == 1) {
printf("The Fibonacci number for %d is ", index);
start = 0;
for (i = 0; i < 200; i++) {
if (start == 0 && fact[index] > 0)
start = 1;
if (start == 1) {
printf("%d", fact[index]);
start = 2;
}
else if (start > 1)
printf("%09d", fact[index][i]);
}
printf("\n");
}
return 0;
}[/cpp]
Thanks,
ec3_limz
P.S. The sample input/output for this problems are too trivial...
