Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 6.30
- Deitel& Deitel C++ How to Program, 10th ed(Indian subcontinent adaptation)
- Visual Studio Community 2019 */
- #include <iostream>
- using namespace std;
- int reverseIt(int test) {
- int reversed{ 0 };
- int aDigit;
- while (test > 0) {
- aDigit = test % 10; // rightmost digit falls off
- test /= 10; // shift number to right
- reversed *= 10;
- reversed += aDigit;
- }
- return reversed;
- }
- int main() {
- int testInt{ 0 };
- int newInt{ 0 };
- cout << "Enter an integer: ";
- cin >> testInt;
- newInt = reverseIt(testInt);
- cout << "Your integer, " << testInt << ", is now " << newInt << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment