I need to write a recursive function to reverse the order of digits in an integer. This is a homework problem, so it has to be done using recursion (not a loop or anything). This is what I've come up with so far:
The problem that I've come across is commetted at the bottom. Any help with solving this would be appreciated. Thanks in advance.Code:public int revDigits (int num) { if (num < 10) { return num; } else { int s = num / 10; int d = num % 10; int i = revDigits(s); return (d * 10) + i; // incorrect // need to find out how many digits in d: //return (d * 10^(num digits in d)) + i); } }




Reply With Quote