# Go Program to Print Even Numbers in an Array

Write a Go program to Print Even Numbers in an Array using For loop. Here, we allow a user to enter the array size and array items. Next, we used for loop (for i = 0; i < evsize; i++) to iterate array items. Within the loop, the if condition (if evenArr[i]%2 == 0) checks whether the item is divisible by two. If True, it is an even so print that number.

```package main

import "fmt"

func main() {
var evsize, i int

fmt.Print("Enter the Even Array Size = ")
fmt.Scan(&evsize)

evenArr := make([]int, evsize)

fmt.Print("Enter the Even Array Items  = ")
for i = 0; i < evsize; i++ {
fmt.Scan(&evenArr[i])
}
fmt.Print("\nThe List of Even Numbers in evenArr = ")
for i = 0; i < evsize; i++ {
if evenArr[i]%2 == 0 {
fmt.Print(evenArr[i], " ")
}
}
fmt.Println()
}```
``````Enter the Even Array Size = 10
Enter the Even Array Items  = 2 7 9 1 8 5 11 22 98 15

The List of Even Numbers in evenArr = 2 8 22 98 ``````

## Go Program to Print Even Numbers in an Array

This Golang example uses the for loop with range.

```package main

import "fmt"

func main() {
var evsize, i int

fmt.Print("Enter the Even Array Size = ")
fmt.Scan(&evsize)

evenArr := make([]int, evsize)

fmt.Print("Enter the Even Array Items  = ")
for i = 0; i < evsize; i++ {
fmt.Scan(&evenArr[i])
}
fmt.Print("\nThe List of Even Numbers in evenArr = ")
for _, ev := range evenArr {
if ev%2 == 0 {
fmt.Print(ev, " ")
}
}
fmt.Println()
}```

In this Golang program, we created a function (printEvenNums(evenArr []int)) to print even numbers within a given array.

```package main

import "fmt"

func printEvenNums(evenArr []int) {
fmt.Print("The List of Even Numbers in evenArr = ")
for _, ev := range evenArr {
if ev%2 == 0 {
fmt.Print(ev, " ")
}
}
}

func main() {
var evsize, i int

fmt.Print("Enter the Even Array Size = ")
fmt.Scan(&evsize)

evenArr := make([]int, evsize)

fmt.Print("Enter the Even Array Items  = ")
for i = 0; i < evsize; i++ {
fmt.Scan(&evenArr[i])
}
printEvenNums(evenArr)
fmt.Println()
}```
``````Enter the Even Array Size = 7
Enter the Even Array Items  = 1 20 98 17 22 0 11
The List of Even Numbers in evenArr = 20 98 22 0 ``````