simple-example.scm 610 B

1234567891011121314151617181920212223242526
  1. ;; (define (factorial n)
  2. ;; (cond
  3. ;; [(> n 1) (* n (factorial (- n 1)))]
  4. ;; [else 1]))
  5. ;; (display "FACTORIAL:") (newline)
  6. ;; (display (factorial 5000)) (newline)
  7. ;; (define (fibonacci n)
  8. ;; (cond [(> n 2)
  9. ;; (+ (fibonacci (- n 1))
  10. ;; (fibonacci (- n 2)))]
  11. ;; [else 1]))
  12. ;; (display "FIBONACCI:") (newline)
  13. ;; (display (fibonacci 1300)) (newline)
  14. (define (factorial-iter n)
  15. (define (iter n product)
  16. (cond [(> n 1) (iter (- n 1) (* product n))]
  17. [else product]))
  18. (iter n 1))
  19. (display "FACTORIAL:") (newline)
  20. (display (factorial-iter 5000)) (newline)