Latest

6/recent/ticker-posts

Write a code to print large fibonacci numbers in minimum time

 1. Write a code to print large fibonacci numbers in minimum time.

CODE:

#include<stdio.h>


int str[10000][1000],k=1;


void fibonacci(int n)

{

while(k<n)

{

int count=0;

for(int j=999;j>=0;j--)

{

int var=str[k][j]+str[k-1][j]+count;

count=var/10;

var = var%10;

str[k+1][j]=var;

}

k++;

}

int i=0;

while(str[n][i]==0 && i<1000)

i++;

for(;i<1000;i++)

{

printf("%d",str[n][i]);

}

printf("\n");

}



int main()

{   int test,j;

    str[1][999]=1;

    printf("how many fibonacci numbers you want to find");

    scanf("%d",&test);

    for(j=0;j<test;j++)

   {

    int n;

      scanf("%d",&n);

      if(n<0)

      printf("error");

      else

     fibonacci(n);


}

return 0;

}

OUTPUT:

Post a Comment

0 Comments