• Source
    1. #include <iostream>
    2. using namespace std;
    3.  
    4. #include<stdio.h>
    5. #define value 5001
    6. #define len 1050
    7. int table[value][len];
    8.  
    9. void fibo()
    10. {
    11. int i,j;
    12. table[0][0]=0;
    13. table[1][0]=1;
    14. table[2][0]=1;
    15.  
    16. for(i=3;i<value ;i++)
    17. {
    18. for(j=0;j<len;j++)
    19. {
    20. table[i][j]+=table[i-2][j]+table[i-1][j];
    21. if(table[i][j]>=10) // if 13 then make 3, 17 then 7
    22. {
    23. table[i][j+1]+=table[i][j]/10;
    24. table[i][j]%=10;
    25. }
    26. }
    27. }
    28. }
    29.  
    30. int main()
    31. {
    32. fibo();
    33. int n,i;
    34. while(scanf("%d",&n)==1)
    35. {
    36. for(i=len-1;i>0;i--)
    37. if(table[n][i]!=0) // if get any value then stop. Avoiding 0.
    38. break;
    39.  
    40. printf("The Fibonacci number for %d is ",n);
    41.  
    42. for(;i>=0;i--) // printing in reverse order
    43. printf("%d",table[n][i]);
    44.  
    45. printf("\n");
    46.  
    47. /* for(i=0;i<10;i++){ Open the comment to see the 2d table
    48.   for(n=0;n<10;n++)
    49.   printf("%d ",table[i][n]);
    50.   printf("\n");
    51.   }
    52. */
    53.  
    54. }
    55. return 0;
    56. }