I need to write a recursive function that will sum all the digits of the given number exept of the most right digit. For example: 56643 -> 5 + 6 + 6 + 4 = 21
Or if the number is 5: the sum will be 0 because we will not sum the right digit (in this example its also our only digit).
I tried to write the recursive function, but without success.
int sumDig(int num) {
if (num < 10)
return 0;
return (num % 10 + sumDig(num / 10));
}
Thanks for everyone