Write a recursive function that takes a non-negative integer as an argument and displays the digits of the integer out in reverse order.
This is my code so far. When I run it, the answer does not come out as reversed. I am not sure what to do next.
thanks.
#include <iostream>
using namespace std;
void printreverse(int x) {
if (x < 10) cout << x; //base case
else {
cout << x % 10;
printreverse(x / 10); //Recursive Cal
}
}
int main()
{
int x;
cout << "Enter integer to reverse : " ;
cin >> x;
cout << "The reversed integer is :" << printreverse;
cin >> x;
system("pause");
return 0;
}
your not calling the function correctly in the main. you need to add a paramter x to printreverse