Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. run this with
  3.  
  4.         clang fib.c
  5.         (or gcc fib.c)
  6.         time ./a.out
  7.  
  8. */
  9. #include <stdio.h>
  10.  
  11. unsigned int fib(int n) {
  12.         if (n <= 2) return 1;
  13.         else return fib(n - 2) + fib(n - 1);
  14. }
  15.  
  16. int main() {
  17.         printf("%u", fib(40));
  18. }
  19.  
  20. /*
  21.  
  22. run this with
  23.  
  24.     time node ./fib.js
  25.  
  26. */
  27. function fib(n) {
  28.   if (n <= 2) return 1;
  29.   else return fib(n - 2) + fib(n - 1);
  30. }
  31.  
  32. console.log(fib(40));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement