Add Digits Problem

Add Digits Problem — ExecCode School DSA Practice

Solve the Add Digits problem on ExecCode. Free online school DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.

Problem description

You are given a number. Your task is to add up all the digits in that number. If your new sum is still more than one digit long, repeat the process. Keep going until you have a sum that is only one digit, then print that digit.

Examples

Input 38; Output 2. Input 9; Output 9

Constraints

1 <= n <= 10^4

Practice Add Digits free on ExecCode. Browse DSA problems, topic map, and placement guides.