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
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
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
i can't use string. my professor said so.
he mention that i need to extract each digits separately.
divide by ten to right shift by one decimal number: 152/10=15 15/10=1.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
- Take a number from the user
- While "number" is more than 0...
- Output "number" % 10
- Divide "number" by 10
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens