Advertisement
Guest User

Untitled

a guest
May 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. fibonacci(n) {
  2. t=0
  3. t1=0
  4. t2=0
  5.  
  6. for(i=0,n){
  7. if(i==0)
  8. {print( 0);}
  9. if(i==1)
  10. {print( 1);}
  11. if(i==2)
  12. {t2=1}
  13. t=t1+t2
  14. t1=t2
  15. t2=t
  16. if(i>1){
  17. print(t2);
  18. }
  19. }
  20. return t
  21. }
  22. write(fibonacci(6));
  23.  
  24.  
  25.  
  26. fibonacci(n) {
  27. if(n == 0) {
  28. return 0
  29. }
  30. if(n == 1){
  31. return 1
  32. }
  33. return fibonacci(n - 1) + fibonacci(n - 2)
  34. }
  35.  
  36. write(fibonacci(6));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement