Write a program which takes a positive integer as input and outputs its digits in reverse. Use integer arithmetic (/ and %) to accomplish this. Always assume the input can fit within the type you use. Give the user an option to repeat the exercise.
Here is a sample run:
Enter a positive integer: 38475
This integer in reverse is 57483.
Would you like to do this again? (y/n) y
Enter a positive integer: 9584
This integer in reverse is 4859.
Would you like to do this again? (y/n) n
Thank you!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main()
{
int num, i = 10;
cout << "Enter a positive integer: ";
cin >> num;
cout << " This integer in reverse is ";
do
{
cout << (num%i) / (i / 10);
i *= 10;
} while ((num * 10) / i != 0);
return 0;
}
So far I am able to reverse the digits of any positive integer. I just don't know how to loop it upon a "yes" or "no" request. Please help me with this assignment.