Question

C++ question #include <iostream> using namespace std; void printReverse(int); int main() {     int number = 12345;...

C++ question

#include <iostream>

using namespace std;

void printReverse(int);

int main() {

    int number = 12345;

    cout << "Original : " << number << endl;

    cout << "Reversed : ";

    printReverse(number);

}

void printReverse(int x) {

    if (x == 0)

       return;

    cout << x % 10;

    printReverse(x /= 10);    

}

Modify the above recursive program to output the number in the same order. Note that the program still should break up the number and then output it in the same order

12345 ? 12345

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>

using namespace std;

void printReverse(int);

int main() {

int number = 12345;

cout << "Original : " << number << endl;

cout << "Reversed : ";

printReverse(number);

}

void printReverse(int x) {

int flag = 0,n,i;

if(x != 0){

printReverse(x/10);

cout<<x%10; // write the statement after the recursive call

}

return;

}

Output:

Add a comment
Know the answer?
Add Answer to:
C++ question #include <iostream> using namespace std; void printReverse(int); int main() {     int number = 12345;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT