Write a program to input an integer N and print the sum of all its even digits and all its odd digits separately.
Digits mean numbers, not the places! If the given integer is "13245", the even digits are 2 and 4, and the odd digits are 1, 3, and 5.
The only line of input contains a single integer N.
Output format:
Print first even sum and then odd sum separated by space.
0 <= N <= 10^8
1234
6 4
552245
8 15
Considering the input provided, we can identify the even digits as 2, 2, and 4. If we add these even digits together, we get 8 (2 + 2 + 4). Similarly, for the odd digits, which are 5, 5, and 5, their sum is 15 (5 + 5 + 5). Therefore, the answer is expressed as 8(evenSum) followed by a single space and then 15 (oddSum).
First, initialize two variables, one as evenSum=0, and the other oddSum=0. Then, For the given input n iterate till n > 0. To get the last digit do, last = n % 10. If your last is even add it to evenSum else add it to oddSum. Now update n as n = n/10.
Finally, print out the values of the variable evenSum and oddSum.