Advertisement
XeBuZer0

Fibonacci's secuence in C (direct)

Dec 21st, 2019 (edited)
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** //
  2. // ** // ** // ** // Código fuente de programa que calcula el n-ésimo término // ** // ** // ** //
  3. // ** // ** // ** // ** // de la secuencia de Fibonacci (directo) // ** // ** // ** // ** // ** //
  4. // ** // ** // ** // * Licenciado bajo GNU General Public License (GPL) 3.0 * // ** // ** // ** //
  5. // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** //
  6. /* ** // ** // ** // ** // ** //  * F v q _ U k r a N a z i s ! * // ** // ** // ** // ** // ** */
  7. /* ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** // ** */
  8.  
  9. #include <math.h>
  10. #include <stdio.h>
  11. #include <errno.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <unistd.h>
  15. #include <sys/time.h>
  16.  
  17. #define Phi (1.0+sqrt(5))/2.0
  18.  
  19. long double FiboDire(long double n);
  20.  
  21. int main(void){
  22.     register long x=0, res=0;
  23.     register long long pre_time=0;
  24.     struct timeval tv;
  25.     for (x=1;x<=35;x++) {
  26.         gettimeofday(&tv, NULL);      
  27.         pre_time = tv.tv_sec*1000000+tv.tv_usec;
  28.         res = FiboDire(x);
  29.         gettimeofday(&tv, NULL);
  30.         printf("Element: %ld Result: %ld Time: %lld\n", x, res, tv.tv_sec*1000000+tv.tv_usec - pre_time);
  31.     }
  32.     return 0;
  33. }
  34.  
  35. long double FiboDire(long double n){
  36.     return (pow(Phi,n)-pow((1.0-Phi),n))/sqrt(5.0);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement