Reputation: 9
How would I formulate the following operation in racket?
(n^2 + 300) (13/n)
?
I got the first part done-
(define (f n)
( + ( * n n ) 300))
So If I type in (f 2)
I would get 304
.
But How do I add the second part of this equation (13/n)
?
Upvotes: 0
Views: 122
Reputation: 22332
If you want to just use direct multiplication, this works:
(define (f n)
(* (+ (* n n) 300) (/ 13 n)))
If all you are going to do is square a number, then you could also do:
(define (f n)
(* (+ (sqr n) 300) (/ 13 n)))
And finally, if you needed to raise n to some power, then you could also do:
(define (f n)
(* (+ (expt n 2) 300) (/ 13 n)))
Upvotes: 4
Reputation: 223003
This is straightforward:
(define (f n)
(* (+ (* n n) 300) (/ 13 n)))
Upvotes: 2