Repeated sum of digits
Submissions: 2172   Accuracy:

58.26%

  Difficulty: Basic   Marks: 1

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:

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

Input:

The first line contains an integer T, total number of test cases. Then following T lines contains an integer N.

Output:

Repeated sum of digits of N.

Constraints:

1 ≤ T ≤ 100

1 ≤ N ≤ 1000000

Example:

Input
2
123
9999

Output
6
9

** For More Input/Output Examples Use 'Expected Output' option **

Author: kartik


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.