Hello coders, today we will be solving Sum of Digits CodeChef Solution whose Problem code is FLOW006.
Problem
You're given an integer N. Write a program to calculate the sum of all the digits of N.
Input
The first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N.
Output
For each test case, calculate the sum of digits of N, and display it in a new line.
Constraints
- 1 <= T <= 1000
- 1 <= N <= 1000000
Example
Input:
3 12345 31203 2123
Output:
15 9 8
Solution - Sum of Digits - CodeChef Solution
Python 3
#Solution provided by Sloth Coders n = int(input()) for _ in range(n): num = input() sum = 0 for i in num: sum += int(i) print(sum)
Disclaimer: The above Problem (Sum of Digits) is generated by CodeChef but the Solution is provided by Sloth Coders.
Happy Coding !!
A Sloth Who loves to Code
Also Read: