how do i display a number backward?

i know i need to use % 10. but if i use this i will only be able to get the tenth digit.

ex 17 % 10 = 7. how do i get the 1 from the first digit? thanks

Printable View

- 11-02-2007nicz888help with displaying a number backward
how do i display a number backward?

i know i need to use % 10. but if i use this i will only be able to get the tenth digit.

ex 17 % 10 = 7. how do i get the 1 from the first digit? thanks - 11-02-2007robatino
If you're allowed to, you could convert the number to a std::string, then reverse that using reverse() from <algorithm>.

http://www.parashift.com/c++-faq-lit....html#faq-39.1

http://www.cppreference.com/cppalgorithm/reverse.html - 11-02-2007nicz888
i can't use string. my professor said so.

he mention that i need to extract each digits separately. - 11-02-2007King Mir
divide by ten to right shift by one decimal number: 152/10=15 15/10=1.

- 11-03-2007hk_mp5kpdw
- Take a number from the user
- While "number" is more than 0...

- Output "number" % 10
- Divide "number" by 10