Created
July 1, 2017 03:25
-
-
Save kanapuli/c2765fe78d2835e008d01eaf1e4d1d3f to your computer and use it in GitHub Desktop.
Golang Implementation to Reverse print an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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