I have an assignment to write a recursive function that writes the digits of a positive integer in reverse order. My problem is that the function doesn\'t display the reverse co
You could use following code (if you do not mind striping leading zeros, or you could accumulate chars in string or ostringstream)
unsigned reverse(unsigned n, unsigned acc)
{
if (n == 0)
{
return acc;
}
else
{
return reverse(n / 10, (acc * 10) + (n % 10));
}
}
unsigned reverse(unsigned n)
{
return reverse(n, 0);
}