Sum Of Digits (Updated) (Hackerearth)

Given number N, print sum of all of its digits.

Input

First Line of input contains integer T denoting number of test cases.
Next T lines contains number N

Output

For each test case, print sum of digits of number N.

Constraints

1 <= T <= 10

Number of digits in N in range [1, 10000000]

SAMPLE INPUT
 
2
123
56666
SAMPLE OUTPUT
 
6
29
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB

Solution

t=int(input())
for i in range (t):
n=int(input())
sum=0
while(n>0):
sum += int(n%10)
n = int(n/10)
print(sum)

Comments

Popular posts from this blog

Reverse words in a given string (GFG)

Chef and Remissness Problem Code: REMISS (CodeChef)

Sort in specific order (GFG)