Challenge 6 - Digit Sums
Finding the digit sum of a number means adding the values of all of its digits. For example, the digit sum of 123 is 1 + 2 + 3 = 6.
A mathematical algorithm for calculating a digit sum is:
- Add the last digit of the number to the sum.
- Set the sum equal to the sum plus the remainder of the number divided by 10.
- Remove the last digit of the number.
- Divide the number by 10, rounding down.
- Repeat the previous two steps while the number is greater than zero.
- Print the sum.
Drag blocks from the left to perform the algorithm, then click the "Run Code" button to see the output.
n
n
sum
0
110
110
ROUNDDOWN1.6
<
n
NUMBER
number =
sum
0
Home