Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. (define (quad-root a b c)
  2. (define eq (- (* b b) (* (* 4 a) c)))
  3. (define eqRoot (sqrt eq))
  4. (define posRoot (/ (+ (- b) eqRoot) (* 2 a)))
  5. (define negRoot (/ (- (- b) eqRoot) (* 2 a)))
  6. (define lst '())
  7. (if (< eq 0); Complex roots
  8. (begin
  9. (set! lst (cons posRoot lst))
  10. (set! lst (cons negRoot lst))))
  11. (if (> eq 0); Real roots
  12. (begin
  13. (if (> posRoot negRoot)
  14. (begin
  15. (set! lst (cons posRoot lst))
  16. (set! lst (cons negRoot lst))))
  17. (if (< posRoot negRoot)
  18. (begin
  19. (set! lst (cons negRoot lst))
  20. (set! lst (cons posRoot lst))))))
  21. lst)
  22. (quad-root 2 9 3)
  23. (quad-root 1 2 3)
  24. (quad-root 349 22 3483)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement