separating the digits of an int so they can be manipulated

Does anyone know a good method to work on the digits of an int separately without using an array?
For instance, if the number was 1234, I need to be able to multiply every other number by 2 and then add them together. ( 1 + (2*2) + 3 + (4*4) ). So I need to be able to isolate the 4 off the end, multiply it, and then isolate the 2 and multiply it...

Obviously if each of the digits were stored in an array it wouldn't be too hard, but this cant be done using arrays. Any ideas?
Without using an array? Off the top of my head divide the number given to you by thousands then hundreds then tens and finally ones. Put each digit in it's own integer then do your manipulations and multiply them by what ever you divided them by in the beggining. This sounds like an excersize in masochism to me but to each their own.
Just do it in one pass.

You only need an array if you want to break the job up into two passes:

1) one to break the digits up into individual ints
2) one to step through the individual ints and sum them (multiplying where appropriate)


Just combine those two steps into the same process.
Topic archived. No new replies allowed.