Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (fast-expt x n)
- (if (even? n)
- (expt (expt x (/ n 2)) 2)
- (expt x n)))
- (define (expt x n)
- (cond ((= n 0) 1)
- ((= n 1) x)
- ((= n -1) (/ 1 x))
- ((< n 0) (* (/ 1 x) (expt x (+ n 1))))
- (else (* x (expt x (- n 1)))))
Add Comment
Please, Sign In to add comment