30 Days of Code - Day 7: Arrays

Coding challenges are a great resource for learning coding techniques and improve analytical thinking, this is a collection of challenges from different platforms.

Objective

Today, we’re learning about the Array data structure. Check out the Tutorial tab for learning materials and an instructional video!

Task

Given an array, A, of N integers, print A’s elements in reverse order as a single line of space-separated numbers.

Input Format

The first line contains an integer, N (the size of our array).

The second line contains N space-separated integers describing array A’s elements.

Constraints:

  • 1 <= n <= 1000
  • 1 <= A[i] <= 10000, where A[i] is the ith integer in the array.

Output Format

Print the elements of array A in reverse order as a single line of space-separated numbers.

Sample

input00.txt
4
1 4 3 2
output00.txt
2 3 4 1

Solution

main.go
package main

import "fmt"

func main() {
  var N int
  fmt.Scan(&N)

  A := make([]int, N)

  for i := 0; i < N; i++ {
    fmt.Scan(&A[i])
  }

  for ; N > 1; N-- {
    fmt.Printf("%v ", A[N-1])
  }

  fmt.Printf("%v", A[0])
}