Recursive digit sum and digital root HARD Subprograme (BAC) 50 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

Write the definition of a **recursive** subprogram `sc` that receives through parameter `n` a natural number (with at most 9 digits) and returns the sum of its digits, computed **recursively** (without using any repetitive statements: `for`, `while`, `do...while`). Also write a subprogram `radacina` that receives through parameter `n` a natural number and returns the digital root of `n`: if `n` has a single digit, return `n`; otherwise return the digital root of the digit sum of `n`. The subprogram `radacina` must use the subprogram `sc`. Then write a main program that reads from standard input a non-zero natural number `t`, then `t` natural numbers `x`, separated by spaces or newlines. For each of the `t` numbers, the program prints on a separate line two values separated by a space: `sc(x)` and `radacina(x)`.

Input format

Input input.txt

The first line contains the natural number `t`. The following lines contain `t` natural numbers. - `1 <= t <= 100` - `0 <= x <= 1.000.000.000` - the subprogram `sc` must be recursive and must not use repetitive statements - the subprogram `radacina` may be recursive or iterative, but must call the subprogram `sc`

Output format

Output output.txt

The program prints `t` lines, each containing two natural numbers separated by a space: the digit sum of `x` and the digital root of `x`, in reading order.

Example

input
3
9875
10000
7
output
29 2
1 1
7 7

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more