Skip to content

Commit fd5527e

Browse files
committed
Repeated sum of digits
1 parent 39c92bf commit fd5527e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Problem Link: https://practice.geeksforgeeks.org/problems/repeated-sum-of-digits/0
3+
4+
Given an integer N, recursively sum digits of N until we get a single digit. The process can be described below
5+
If N < 10
6+
digSum(N) = N
7+
Else
8+
digSum(N) = Sum(digSum(N))
9+
10+
Example:
11+
Input : 1234
12+
Output : 1
13+
Explanation : The sum of 1+2+3+4 = 10,
14+
digSum(x) == 10
15+
Hence ans will be 1+0 = 1
16+
17+
Input:
18+
The first line contains an integer T, total number of test cases. Then following T lines contains an integer N.
19+
20+
Output:
21+
Repeated sum of digits of N.
22+
23+
Constraints:
24+
1 ≤ T ≤ 100
25+
1 ≤ N ≤ 1000000
26+
27+
Example:
28+
Input
29+
2
30+
123
31+
9999
32+
33+
Output
34+
6
35+
9
36+
"""
37+
for _ in range(int(input())):
38+
n = int(input())
39+
if n == 0:
40+
print(0)
41+
elif n % 9 == 0:
42+
print(9)
43+
else:
44+
print(n%9)

0 commit comments

Comments
 (0)