logo CodeStepByStep logo


Language/Type: Racket
Author: Melissa Hovik (on 2017/07/08)

Define a function named digit-sum that accepts an integer n and returns the sum of its digits. For example, the call (digit-sum 341) should return 8 (since 3 + 4 + 1 = 8). If passed a negative parameter, the function should return the negative sum of the digits. For example, the call (digit-sum -341) should return -8 (since -(3 + 4 + 1) = -8). You may assume that only integers are passed as arguments.

Type your Racket solution code here:

This is a function exercise. Write a Racket function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.