Print array#8953

Print array (Editorial)

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 .

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 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 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 of integers, using a separator.

print(*lst, sep='\n')