0
$\begingroup$

How to write a pseudocode to split a number value to array of numbers? Let's say the number value is 12345. I need to convert it into [1,2,3,4,5].

$\endgroup$
1
0
$\begingroup$
num_to_arr(num):
   length_of_arr = log(num)+1 //log(num) base 10
   arr[length_of_arr]
   digit = 0

   while num > 0:
      digit = num % 10
      arr[length_of_arr - 1] = digit
      length_of_arr = length_of_arr - 1
      num = num / 10

return arr

This should do the job.

$\endgroup$
3
  • $\begingroup$ It must be strictly [1,2,3,4,5] $\endgroup$
    – camille
    Feb 5 '20 at 15:45
  • $\begingroup$ @camille Check the solution, I have added $\endgroup$
    – Breakpoint
    Feb 5 '20 at 15:54
  • $\begingroup$ thank you for the solution $\endgroup$
    – camille
    Feb 5 '20 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.