digital-root

Calculate the digital root of a number

A digital root, according to Wikipedia, is "the number obtained by adding all the digits, then adding the digits of that number, and then continuing until a single-digit number is reached." For instance, the digital root of 99 is 9, because 9 + 9 = 18 and 1 + 8 = 9. My Haskell solution -- and I'm no expert -- is as follows. digitalRoo...

Calculating Digital Root, is there a better way ?

Hello This is how i calculated the digital root of an integer. import acm.program.*; public class Problem7 extends ConsoleProgram { public void run() { println("This program calculates the digital root of an interger."); int num = readInt("Enter the number: "); int sum = 0; while (true) ...