Question & Answer: Write a recursive C++ function that writes the digits of a positive decimal integer in rever…..

Write a recursive C++ function that writes the digits of a positive decimal integer in reverse order.

Expert Answer

 

Program :

#include <iostream>
using namespace std;
void numReverse(int num)
{
if(num>0)
cout << (num%10);
if(num)
numReverse(num/10);
}

int main()
{
int number;
cout << “Enter number to reverse : “;
cin >> number;
cout<< “The reverse of the number is “;
numReverse(number);
return 0;
}

Output :

Still stressed from student homework?
Get quality assistance from academic writers!