Question: Language: C++ Q1. [Digital Root] The digital root is one single-digit value obtained by summing the digits of a non-negative integer number iteratively. In each
Language: C++
![Language: C++ Q1. [Digital Root] The digital root is one single-digit value](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4fa87720d8_95066f4fa86e71cb.jpg)
Q1. [Digital Root] The digital root is one single-digit value obtained by summing the digits of a non-negative integer number iteratively. In each iteration, please compute the digit sum of the result from the previous iteration until a single-digit number is reached. For example, the digital root of 24 is 2 + 4 = 6, because 6 is a single-digit number. For 39, we compute 3 +9 = 12 first and find that 12 is not a single-digit number. Then we continue to compute the digit sum of 12 (the previous iteration's result) and finally get the digit root of 39 is 1+ 2 = 3. For a single-digit integer, the digital root is itself. Given a non-negative integer (data type: int) N, please write a program to print its digital root. The program needs to check the correctness of this input. If N is negative, the user needs to input another N value again. Here are two examples. Note: You only need to use the content learnt from Lectures 1 to 5. Example 1: Please input a positive number: -1 Invalid input! Please input a positive number: 189 The digital root is: 9 Example 2: Please input a positive number: 8943 The digital root is: 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
