Skip to content

Instantly share code, notes, and snippets.

@jtprogru
Created May 12, 2022 20:34
Show Gist options
  • Save jtprogru/7abe8ecd235679e08821db64e43fe873 to your computer and use it in GitHub Desktop.
Save jtprogru/7abe8ecd235679e08821db64e43fe873 to your computer and use it in GitHub Desktop.
Сначала задано число N — количество элементов в массиве (1≤N≤100). Далее через пробел записаны N чисел — элементы массива. Массив состоит из целых чисел. Необходимо вывести все элементы массива с чётными индексами.
package main
import "fmt"
func main() {
var inputNumber int
var outputStr string
_, _ = fmt.Scan(&inputNumber)
inputArray := make([]int, inputNumber)
_, _ = fmt.Scan(&inputArray)
for i := 0; i < inputNumber; i++ {
_, _ = fmt.Scan(&inputArray[i])
}
for k, v := range inputArray {
if k%2 == 0 {
outputStr += fmt.Sprintf("%d ", v)
}
}
fmt.Println(outputStr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment