Problem 72
Sum of Digits
Easy · 10 pts · Math
Problem
You are given a non-negative integer N. Print the sum of its decimal digits. Repeatedly take the last digit with N mod 10, add it to the total, and remove it with integer division N / 10, until N becomes 0. N can be as large as 10^18, so read it into a 64-bit integer (or simply read it as a string and add up its characters).
Input
A single integer N.
Output
Print the sum of the digits of N.
Constraints
0 <= N <= 10^18
Example input
1234
Example output
10
Explanation
The digits of 1234 are 1, 2, 3 and 4. Their sum is 1 + 2 + 3 + 4 = 10.