1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Checksum(n) = CHKSUM(n)

  1. Aug 12, 2006 #1
    pre n >= 0
    post checksum(n) = CHKSUM(n)
    reads 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. jcsd
  3. Aug 12, 2006 #2
    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.
     
  4. Aug 12, 2006 #3
    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
     
  5. Aug 13, 2006 #4
    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?
     
  6. Aug 13, 2006 #5
    pls show me how to write this recursive algorithm.I need it very much,pls

    thanx
     
  7. Aug 13, 2006 #6

    0rthodontist

    User Avatar
    Science Advisor

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Checksum(n) = CHKSUM(n)
Loading...