Advertisement
XeBuZer0

Fibonacci's secuence in C (recursive)

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