Skip to content

Instantly share code, notes, and snippets.

@kanapuli
Created July 1, 2017 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanapuli/c2765fe78d2835e008d01eaf1e4d1d3f to your computer and use it in GitHub Desktop.
Save kanapuli/c2765fe78d2835e008d01eaf1e4d1d3f to your computer and use it in GitHub Desktop.
Golang Implementation to Reverse print an array
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
var totalNumbers int //To get the initial length of the array
var temp string //To hold the array items
fmt.Scanf("%d", &totalNumbers)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
temp = scanner.Text()
break
}
array := strings.Split(temp, " ")
array = array[0:totalNumbers]
for i := totalNumbers - 1; i >= 0; i-- {
fmt.Printf("%v ", array[i])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment