Guest User

Untitled

a guest
Nov 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. (define (fast-expt x n)
  2. (if (even? n)
  3. (expt (expt x (/ n 2)) 2)
  4. (expt x n)))
  5.  
  6. (define (expt x n)
  7. (cond ((= n 0) 1)
  8. ((= n 1) x)
  9. ((= n -1) (/ 1 x))
  10. ((< n 0) (* (/ 1 x) (expt x (+ n 1))))
  11. (else (* x (expt x (- n 1)))))
Add Comment
Please, Sign In to add comment