Reversing integers.

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
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
Here are hundreds ways to do it.
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.
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
Just a small heads-up: be careful for numbers that include a 0. Depending on your implementation, they can really ruin things.
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
Topic archived. No new replies allowed.