The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.
Given a large number N, the task is to find its digital root. The input number may be large and it may not be possible to store even if we use long long int.
Input: N = 675987890789756545689070986776987
Sum of individual digit of the above number = 212
Sum of individual digit of 212 = 5
So the Digital root is 5
Input: num = 876598758938317432685778263
Sum of individual digit of the above number = 155
Sum of individual digit of 155 = 11
Sum of individual digit of 11 = 2
So the Digital root is 2
- Find out all the digits of a number.
- Add all the number one by one.
- If the final sum contains more than one digit, Call the recursive function again to make it a single digit.
- The result obtained in the single-digit is the Digital Root of the number.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Digital Root (repeated digital sum) of square of an integer using Digital root of the given integer
- Digital Root (repeated digital sum) of the given large integer
- Multiply large integers under large modulo
- Numbers in a Range with given Digital Root
- Sudo Placement[1.7] | Greatest Digital Root
- Print a number containing K digits with digital root D
- Find Nth positive number whose digital root is X
- Convert a String to an Integer using Recursion
- Smallest root of the equation x^2 + s(x)*x - n = 0, where s(x) is the sum of digits of root x.
- Square root of an integer
- Minimum decrements to make integer A divisible by integer B
- Decimal to Binary using recursion and without using power operator
- Add the given digit to a number stored in a linked list using recursion
- Traverse a given Matrix using Recursion
- Count the occurrence of digit K in a given number N using Recursion
- Create a Circular List Structure For Given Value K Using Recursion
- Print even and odd numbers in a given range using recursion
- Find square root of number upto given precision using binary search
- Large number arithmetic using doubly linked list
- Multiply Large Numbers using Grid Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.