Name: Anonymous 2010-03-06 15:02
YASHT - Yet Another Stupid Homework Thread
Write a function that returns the value of any number raised to an integer power in the language of your choice. Positives, negatives, the whole nine yards.
Here's my Scheme implementation:
EXTRA CREDIT Write one that raises numbers to non-integer powers. I don't know the math behind that, so I couldn't do it.
Write a function that returns the value of any number raised to an integer power in the language of your choice. Positives, negatives, the whole nine yards.
Here's my Scheme implementation:
(define (power n pow)
(cond ((> pow 1) (* (power n (- pow 1)) n))
((= pow 1) n)
((= pow 0) 1)
(else (/ 1 (power n (* pow -1))))))EXTRA CREDIT Write one that raises numbers to non-integer powers. I don't know the math behind that, so I couldn't do it.