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].
-
2$\begingroup$ Hi, welcome to cs.stackexchange. The answer you are searching is already on stackoverflow in a slightly different form. stackoverflow.com/questions/780390/… $\endgroup$– ApoorvFeb 5, 2020 at 15:52
1 Answer
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.
-
-
$\begingroup$ @camille Check the solution, I have added $\endgroup$ Feb 5, 2020 at 15:54
-