Jun 1, 2010

PPP: The Sum of Digits

A Programing Practice Problem where the user provides a positive integer to receive back the total of the digits in the given number.

Sum of Digits

Provide me with an application that takes an input int and returns an int that is the total of each digit of that number. In the case of 1024, it should return 7, as 1 + 0 + 2 + 4 = 7. Be sure that anything from a single digit number to an 8 digit or higher number still runs correctly.

Single Digit Sum of Digits

Taken to the next step, repeat the process over and over until the return value is a single digit number.

Extra Credit: Crazy Mode

Allow the user to change the app away from base 10, such as base 2 or base 16. This is called crazy for a reason.