Write in Racket Language
Write a recursive Racket function "sum" that takes two integers as parameters, each greater or equal to zero, and evaluates to their sum. In this problem, you must use the built-in functions "add1" and "sub1" and may not use the built-in functions "+" or "-". For example, (sum 2 3) should evaluate to 5. Note: (add1 5) evaluates to 6 and (sub1 4) evaluates to 3. Hint: like you saw in the "append" lecture, treat one of the parameters as the size of the problem and recurse until it reaches your base case.
Greetings!!!!!
Please find the recursive racket function as below, which makes use of add1 and sub1 built-in funcitons. Screen shots of all possible sample run is also attached below the function.
(define (sum n m)
(if (= n 0)
m
(if (= m 0)
n
(sum (add1 n) (sub1 m)))))
Thank You
Get Answers For Free
Most questions answered within 1 hours.