15.0k views
2 votes
Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Assume that the list will always contain less than 20 integers.

1 Answer

5 votes

Final answer:

The question asks for a program to read a list of integers and output them in reverse. A program in Python uses a loop to collect the integers and then outputs them reversed, each followed by a space. The solution ensures the list is fewer than 20 integers.

Step-by-step explanation:

To create a program that reads a list of integers and outputs them in reverse order, you can use a simple loop structure in a programming language such as Python. This program assumes the input begins with an integer representing the count of numbers that will follow. It then reads that many integers into a list, and prints them out in reverse order with a space following each integer, as per the requirement.

Here is an example of how such a program could look in Python:

num_count = int(input('Enter the number of integers: '))
integers = []
for _ in range(num_count):
integers.append(int(input('Enter an integer: ')))
for integer in reversed(integers):
print(integer, end=' ')
The reversed function is used here to iterate through the list in reverse order. The assumption is that the user's input list will always contain less than 20 integers as stated in the problem.
User John Kemeny
by
5.1k points