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
This is a discussion on help with displaying a number backward within the C++ Programming forums, part of the General Programming Boards category; how do i display a number backward? i know i need to use % 10. but if i use this ...
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
I used to be an adventurer like you... then I took an arrow to the knee.