CodeMIRAI
0 XP

Sum of digits

Medium +50 XP Solved

Read a non-negative whole number and print the sum of its digits. For 9045, print 18.

Input
9045
Expected output
18
Input
0
Expected output
0
Show a hint

n % 10 gives the last digit; n /= 10 removes it.

Show a solution
C++
Loading the editor…
Run the tests to check your solution.