Just a simple question,

is it possible if given an input of an integer to count how many digits that integer have and assign each digit to an element of an array using only 1 loop?

is it possible if given an input of an integer to count how many digits that integer have and assign each digit to an element of an array using only 1 loop?

Certainly. What is stopping you? You want an array with [x % 10, x / 10 % 10, x / 100 % 10, ...] right? Is this a problem about finding the length of the array (e.g. want the array to start with the most significant digit)? You can use the fact that x has log10(x)+1 digits or that an integer can have at most 10 digits.

Topic archived. No new replies allowed.