Geeksforgeeks

Error

×

Given an integer N, recursively sum digits of N until we get a single digit. The process can be described below

```
If N < 10
digSum(N) = N
Else
digSum(N) = Sum(digSum(N))
```

**Example 1:**

Input:N = 1234Output:1Explanation:The sum of 1+2+3+4 = 10, digSum(x) == 10 Hence ans will be 1+0 = 1

**Example 2:**

Input:N = 9999Output:9Explanation:Check it yourself.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function repeatedSumOfDigits() which takes an integer N and returns the repeated sum of digits of N.

**Expected Time Complexity:** O(1)

**Expected Auxiliary Space:** O(1)

**Constraints: **

1 ≤ N ≤ 1000000

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Repeated sum of digits

...