Even Digit Sum
easySave
Math
Given a non-negative integer, calculate the sum of its digits that are even. Return the calculated sum.
Example 1
Input
[ 2468 ]
Output
20
Explanation. The digits of 2468 are 2, 4, 6, 8. All are even, and their sum is 20.
Example 2
Input
[ 12345 ]
Output
6
Explanation. The digits of 12345 are 1, 2, 3, 4, 5. Even digits are 2 and 4, and their sum is 6.
Example 3
Input
[ 0 ]
Output
0
Explanation. The digit is 0, which is even, and its sum is 0.
Example 4
Input
[ 7 ]
Output
0
Explanation. The digit is 7, there are no even digits, thus the sum is 0.
Example 5
Input
[ 1111 ]
Output
0
Explanation. The digits are all 1, which are odd. Thus, no even digits and the sum is 0.
Follow-up: How would you handle large numbers beyond standard integer limits in languages like Python?
Constraints:
The input will always be a non-negative integer.
- Views
- 2