Try to write these recursive functions. Do not use any loops. Test your functions by calling them from setup()
.
A function int sumDigits(int n)
that computes the sum of the digits of a number. Examples: sumDigits(123)
is 6
, sumDigits(7302)
is 12
, and sumDigits(4)
is 4
. Note: The modulus operator %
is your friend.
A function int addZeroes(int n)
that inserts a 0
between every two digits. Examples: addZeroes(123)
is 10203
and addZeroes(8)
is 8
.
A function int reverseDigits(int n)
that reverses the digits in a number. Examples: reverseDigits(123)
is 321
and reverseDigits(6)
is 6
.