Answer:
The programs are written in python:
Version 1:
n = int(input("Numbers: "))
for i in range(n):
num = int(input("Input integer: "))
mylist = []
while num>0:
mylist.append(num%10)
num= int(num/10)
mylist.reverse()
for i in mylist:
print(i,end=" ")
print()
Version 2:
num = int(input("Input integer: "))
while num > 0:
mylist = []
while num>0:
mylist.append(num%10)
num= int(num/10)
mylist.reverse()
for i in mylist:
print(i,end=" ")
print()
num = int(input("Input integer: "))
Step-by-step explanation:
Version 1:
This gets the number of inputs from the user, n
n = int(input("Numbers: "))
This iterates through n
for i in range(n):
For each iteration, this gets the integer input from the user, num
num = int(input("Input integer: "))
This initializes a list
mylist = []
This loop is repeated until num is 0
while num>0:
This gets the individual digit and appends it to a list
mylist.append(num%10)
This gets the other numbers
num= int(num/10)
This reverses the list
mylist.reverse()
This prints the individual digits from the list
for i in mylist:
print(i,end=" ")
Print a new line for the next integer input
print()
Version 2:
The difference in both versions are the following lines
This gets the integer input from the user
num = int(input("Input integer: "))
This loop enables the user to input as many numbers as possible. But once the user inputs 0, the program will stop
while num > 0:
Unlike version 1 where the number of inputs in known at the initial stage of the program