Home /
Expert Answers /
Computer Science /
the-digital-root-of-an-positive-integer-n-is-the-number-obtained-by-adding-all-the-digits-of-pa115
(Solved):
The digital root of an positive integer \( N \) is the number obtained by adding all the digits of ...
The digital root of an positive integer \( N \) is the number obtained by adding all the digits of \( N \), then adding the digits of that number, and then continuing until a single-digit number is reached. For example, to calculate the digit number of 32768 , one first calculate \( 3+2+7+6+8=26 \); Since \( 26 \geq 10 \), then we need to further evaluate \( 2+6=8 \). Since \( 8<10 \), the digital root of 32768 is 8. Write a program digital root.cpp that takes in an integers, and prints out its digital root. In your program, you should implement a function int digitroot (int \( N \) ) that calls itself recursively to evaluate the digital root of \( N \). You should also write a main function to receive input \( N \) and call the function digitroot to compute the digital root of \( N \). Please have the output formatted like the following examples: Input: 83463 Digit root: 6 Input: 9999 Digit root: 9 Input: 5 Digit root: 5 - No invalid inputs: You do NOT have to worry about the user giving invalid inputs like negative integers, double numbers, etc.