Reversing integers.

Mar 16, 2012 at 4:01am
I'm supposed to write a program for class that takes an integer and reverses it. For example, 123 would become 321. I don't even know where to begin. I have looked at some similar examples online, but I don't understand. Thank you.
Last edited on Mar 16, 2012 at 4:15am
Mar 16, 2012 at 4:32am
You might want to take a look at arrays.

Once you've familiarized yourself with arrays, you can use a for-loop to easily flip the digits around. Let me know if you need an example - I'd be glad to help.
Last edited on Mar 16, 2012 at 4:33am
Mar 16, 2012 at 6:20am
Here are hundreds ways to do it.
Mar 16, 2012 at 10:42am
take 123 for example.
break it into 3 seperate digits i-e 1 2 3
store them in seperate variables.
display them.
to break them :-

123/100 =1
123%100 = 23

store 1 in seperate variable.

23/10 = 2
23%10 =3

store 2 in a seperate variable.

then store 3 in seperate variable.

display them in whatever order you want them to be.
same tecqnique can be used for palindrome and armstrong number test.
Mar 16, 2012 at 11:18am
I stick with code assassin,use arrays and a for/while loop to reverse the order.store each variable in different spaces in the same arrays and display 'em by accessing each array space
Last edited on Mar 16, 2012 at 11:19am
Mar 16, 2012 at 11:21am
Just a small heads-up: be careful for numbers that include a 0. Depending on your implementation, they can really ruin things.
Mar 16, 2012 at 2:09pm
Thank you! I think I understand now. My only problem now is that it has to be able to work for integers with any number of digits. I guess I'll have to use a loop of some kind, but I don't know what to do.

My instructor just told us that we can use arrays, but I have to use reference parameters somehow.
Last edited on Mar 16, 2012 at 3:06pm
Topic archived. No new replies allowed.