An array of n integers is
given. Print all its elements in a single column, do not change their initial
order.
Input. The first line contains the number n
(1 ≤ n ≤ 100). The second
line contains n integers, each no
more than 100 by absolute value.
Output. Print each element of the array on a separate line.
Sample input |
Sample output |
7 0 -3 4 5 -7
2 -3 |
0 -3 4 5 -7 2 -3 |
array
The problem can be solved using a loop. Read and print each element of
the array immediately, one per line.
Alternatively, the problem can be solved using an array. First, read the
input sequence into an array. Then, print its elements in the specified order.
Algorithm
implementation
Read the value of n.
scanf("%d", &n);
Read the
elements of the array in a
loop
and print them one
by one, each on a new line.
for (i = 0; i < n; i++)
{
scanf("%d", &a);
printf("%d\n", a);
}
Algorithm
implementation – array
Declare an array to store the sequence.
int m[101];
Read the input data.
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &m[i]);
Print an array of integers,
each on a separate line.
for (i = 0; i < n; i++)
printf("%d\n", m[i]);
Java implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new
Scanner(System.in);
int n = con.nextInt();
int m[] = new int[n];
for (int i = 0; i < n; i++)
m[i] = con.nextInt();
for (int i = 0; i < n; i++)
System.out.println(m[i]);
con.close();
}
}
Python implementation
Read the input data.
n = int(input())
lst = list(map(int,input().split()))
Print a list lst of integers, each on a
separate line.
for i in
range(n):
print(lst[i])
Python implementation – list
Read the input data.
n = int(input())
lst = list(map(int,input().split()))
Print a list lst of integers, each on a
separate line.
for x in lst:
print(x)
Python implementation – separator
Read the input data.
n = int(input())
lst = list(map(int,input().split()))
Print a list lst of integers, using a
separator.
print(*lst, sep='\n')