# Homework Help: Checksum(n) = CHKSUM(n)

1. Aug 12, 2006

### teng125

pre n >= 0
post checksum(n) = CHKSUM(n)
changes -
mem -

Remark: Let n be an integer number. Furthermore, CHKSUM(n) = “sum of digits of n”. checksum is the name of the module to be developed.

Develop a recursive algorithm for the above specification. Assume and use functions
div function and mod function.

can smby pls show me how to write this algorithm

thanx

2. Aug 12, 2006

### buddyholly9999

Well first off, you need to know exactly what your algorithm is supposed to do. Looks like your CHKSUM(n) is supposed to find the sum of the digits of n. So, take an example. If you have n = 198...then checksum should return what value?

After that it should be pretty straightforward, if you know what value it's supposed to be.

3. Aug 12, 2006

### teng125

does it means sum up all the values from 1 to 198 if n=198??
actually i don'tknow what does the algorithm above means at all

why does it needs to use functions div function and mod function.

if possible,pls explain to me

thanx

4. Aug 13, 2006

### buddyholly9999

No it does not mean that...it means to sum up the "digits" that make up the number 198. So the number 198 is made up of 3 "digits"...which numbers and what is their sum?

5. Aug 13, 2006

### teng125

pls show me how to write this recursive algorithm.I need it very much,pls

thanx

6. Aug 13, 2006

### 0rthodontist

We're not going to do your problem for you.

The checksum of 198 should be 1 + 9 + 8 = 18.
Here is another hint: 198 mod 10 = 8.
(198 - 198 mod 10) / 10 = 19