### Reverse Of A Number.

write a program which accepts a number and displays the reverse of the number.
ex. input: 789
output: 987
It will be something like this. This program takes 3 numbers and displays them in increasing order. Use this format for your program. Let me know if you have questions.

 1234567891011121314151617181920212223242526272829303132333435363738 #include using namespace std; int main(){ // inputs the numbers cout << "Enter three numbers: "; int one, two, three; cin >> one >> two >> three; int tmp; // orders one and two if (one > two){ tmp = one; one = two; two = tmp; } // orders two and three if (two > three){ tmp = two; two = three; three = tmp; } // orders one and two if (one > two){ tmp = one; one = two; two = tmp; } // outputs the sorted numbers cout << "The sorted numbers are: "; cout << one << " " << two << " " << three << endl; }

http://www.cplusplus.com/forum/beginner/812/
int reverse_num(int sourcenum)
{
int temp = sourcenum;
int sum = 0;
while (temp)
{
sum*=10;
sum += temp%10;
temp/=10;
}
return sum;
};
or use c++ homework help
http://www.cpp4u.com/cpp_homework_help.html
Last edited on
Can you use strings, because if you can - then string::reverse_iterator would work for you perfect.

 123456 string num; cout << "Enter num"; getline(cin, num); for (string::reverse_iterator rit=num.rbegin; rit!=num.rend; ++rit){ cout << *rit;
Last edited on
Topic archived. No new replies allowed.