Digit Sum (Repeatedly Until Single Digit)

E · easyP · Verified PYQmath

Given a number N, repeatedly sum its digits until you get a single digit. Print that digit. Example: 9875 → 9+8+7+5 = 29 → 2+9 = 11 → 1+1 = 2

Input
9875
Output
2
Digital root formula: 1 + (n-1)%9 for n>0. Or loop: while n>=10: n = sum of digits.
← Decimal to BinaryFactorial of a Number →
Report an issue with this question