Skip to content
C

Sum of Digits

Easypython

Read a whole number and print the sum of its digits, using a while loop.

Approach: repeatedly take the last digit with n % 10, add it to a running total, then remove that digit with n //= 10, until n becomes 0.

Input: One line: a whole number n (may be negative — use its digits regardless of sign).

Output: One line: Sum of digits: <total>

Input (stdin)

Output

Run your code to see output here...