(Reverse Digits) Write a function that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the function should return 1367.
What will be an ideal response?
```
// Reverse the digits of a number.
#include
#include
using namespace std;
int reverseDigits( int ); // function prototype
int main()
{
int number; // input number
cout << "Enter a number between 1 and 9999: ";
cin >> number;
cout << "The number with its digits reversed is: ";
// find number with digits reversed
cout << reverseDigits( number ) << endl;
} // end main
// reverseDigits returns number obtained by reversing digits of n
int reverseDigits( int n )
{
int reverse = 0; // reversed number
// loop until zero
while ( n > 0 )
{
reverse *= 10; // shift digits in reverse left
reverse += n % 10; // add least-significant digit of n to reverse
n /= 10; // remove least-significant digit from n
} // end while
return reverse; // return reversed number
} // end function reverseDigits
```
You might also like to view...
The class ObjectInputStream contains all of the following methods except:
(a) readLine() (b) readChar() (c) readObject() (d) readInt()
____ layouts use ems instead of pixels as the unit for div and text styles.
A. Liquid B. Elastic C. Fixed-width D. Indexed
Open the ___________ panel and click File Properties to view information about a file in Adobe Bridge.
Fill in the blank(s) with the appropriate word(s).
Blends can only be made between closed paths.
Answer the following statement true (T) or false (F)