How to write exponent in racket?
14,676
Solution 1
Use the primitive function expt
(see reference):
(expt x 4) ; = x⁴
Solution 2
If you forget expt
, you can use:
(for/product ((i 4)) x)
It's easier than writing (* x x x x)
for larger values.
Author by
Yamin Momo
Updated on June 14, 2022Comments
-
Yamin Momo almost 2 years
Using
(x^4)
or (^ x 4) giving an error message. Is there some functions for exponent than simply using(* x x x x)
?