Sum of Three Digits
Completed
Read a three-digit positive integer and print the sum of its digits using only arithmetic (// and %), not strings.
Input
An integer from 100 to 999.
Output
The sum of its digits.
Example
Input
123
Output
6
Editor
Python
Hints
n % 10 is the last digit.
n // 10 % 10 is the middle digit, n // 100 the first.
Solution explanation
Dividing by 10 shifts digits right; % 10 picks the last one.
Show solution
n = int(input())
print(n // 100 + n // 10 % 10 + n % 10)