Write a recursive function named printReverse() that displays a non-negative int
ID: 3622414 • Letter: W
Question
Write a recursive function named printReverse() that displays a non-negative integer’s
digits in reverse order. The following program presents a test driver with the function prototype. Complete the function definition part.
#include
using namespace std;
// function prototype
int printReverse(unsigned n);
int main()
{
int n;
for (;;)
{
cout << "Enter a nonnegative integer (-1 to stop): ";
cin >> n;
if (n < 0) break;
cout << " Reversal is: " << printReverse(n) << endl;
}
}
int printReverse (unsigned n)
{
// Complete your code
}
Sample Run:
Enter a nonnegative integer (-1 to stop): 5
Reversal is : 5
Enter a nonnegative integer (-1 to stop): 123
Reversal is: 321
Enter a nonnegative integer (-1 to stop): 75
Reversal is: 57
Enter a nonnergative integer (-1 to stop): -1
Explanation / Answer
#include using namespace std; // function prototype int printReverse(unsigned n); int main() { int n; for (;;) { cout > n; if (n < 0) break; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.