Twenty-eighth

#include <stdio.h>

#include <time.h>

long fib (int n) {    

return n<=2 ? 1 : fib(n-1)+fib(n-2);

}  

void main ()

{    double x;  

     int n;    

     for(n=2;n<=45; n++)    {      

           x = clock() / CLOCKS_PER_SEC;      

           printf("fib(%d)=%ld  ",n,fib(n));    

           x = clock() / CLOCKS_PER_SEC - x;    

           printf("Timing fib(%d): %f.\n",n,x);    

     }

     return 0;

}

猜你喜欢

转载自blog.csdn.net/sutiesenn/article/details/82974967