Learn
Exam

Calculate the Sum of Each Digit

Difficulty
STARTER

Problem

Write a function solution that returns the sum of the digits of the given natural number number.


Constraints

  • number is a natural number between 1 and 10^18 inclusive.

Test Case

Test Case Number number return
1 12345 15
2 9876543210 45
3 1000000000000000001 2

Explanation for Test Case 1

  • When number = 12345, the sum of the digits is 1 + 2 + 3 + 4 + 5 = 15.

Explanation for Test Case 2

  • When number = 9876543210, the sum of the digits is 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 + 0 = 45.

Explanation for Test Case 3

  • When number = 1000000000000000001, the sum of the digits is 1 + 0 + 0 + ... + 0 + 1 = 2.