-3

I could use some help with a program for school in order to do so I need to put the position of the number in array: For example if I introduce 10582 the first position of the array is gonna be 2, the second 8, the third 5, the fourth 0, and the last 1.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

1 Answers1

0

It sounds like what you want is to extract each digit from a number and store them separately.

That being the case, you can use the modulus operator (%) to get the remainder of dividing by 10. That will give you the rightmost digit. Then you would divide the number by 10 to shift the rightmost decimal digit off.

Repeat the process until you're left with 0.

dbush
  • 205,898
  • 23
  • 218
  • 273