Anyone know a algorithm to reverse a number's order?.:Resovled:.
Hello everyone,
I'm trying to figure out how i'm suppose to ouput a number reversed, such as, 123 output it as 321.
I'm not allowed to use arrays so i'm thinking there has to be a mathamatical way of doing this. There is no fixed amount of numbers, it can be 2 to whatever the user wants to enter, any idea's? Like this almost worked....
input: 155
155%10 = 5;
15%10 = 5;
10%10 = 0;
almost got 551 :(
% is mod in C++ but u all probably knew that just making sure!
Thanks for listening:D
Re: Anyone know a algorithm to reverse a number's order?
Quote:
Originally posted by voidflux
Hello everyone,
I'm trying to figure out how i'm suppose to ouput a number reversed, such as, 123 output it as 321.
I'm not allowed to use arrays so i'm thinking there has to be a mathamatical way of doing this. There is no fixed amount of numbers, it can be 2 to whatever the user wants to enter, any idea's? Like this almost worked....
input: 155
155%10 = 5;
15%10 = 5;
10%10 = 0;
almost got 551 :(
% is mod in C++ but u all probably knew that just making sure!
Thanks for listening:D
10%10 = 0 -- yep, that's true.... mod returns the remainder after division
1%10 = 1
2%10 = 2
3%10 = 3
4%10 = 4
5%10 = 5
6%10 = 6
7%10 = 7
8%10 = 8
9%10 = 9
10%10 = 0