Problem #1EasyMaths
Sum of Digits
Time Limit: 10s
Memory Limit: 256MB
Sum of Digits
Problem Description
Given a non-negative integer N, write a program to calculate and print the sum of all its digits.
The sum of digits is obtained by adding each individual digit of the given number. For example, if the given number is 1234, the sum of its digits is 1 + 2 + 3 + 4 = 10.
If the number is 0, its sum of digits is 0.
Input Format
- A single integer N, representing the number whose digits need to be summed.
Output Format
- Print a single integer representing the sum of all digits of N.
Examples
Example 1:
Input:
12345
Output:
15
Example 2:
Input:
908
Output:
17
Constraints
- The input number
Nwill be a non-negative integer. - The value of
Nwill be in the range of 0 to 10^9 (inclusive). - The number may contain one or more digits.
- The input will not contain any decimal points, special characters, or alphabetic characters.
- If
Nis0, the sum of its digits will be0. - The output must be a non-negative integer representing the sum of all the digits of
N.
Sample Test Cases
Example 1
Input:
12345
Expected Output:
15
Example 2
Input:
1001
Expected Output:
2