GO Program to print positive numbers in an array

How to print positive numbers in an array

Here we are explaining how to print positive numbers in an array in the Go program. We can use the built-in function fmt.println() to print anything and fmt.scanln() for reading the values. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.


How to print positive numbers in an array using GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to print positive numbers in an array in the Go language. Here variable Arr holds the array elements. Other variables size, i used as the size of the array and index for the loop. Use for loop to find the positive numbers by iterating through the loop. If (Arr[i] >= 0) then it is a positive number and print that number. Given below are the steps which are used in the Go program. 


STEP 1: Import the package fmt

STEP 2: Start function main()

STEP 3: Declare the variable size,i

STEP 4: Read the array Arr[] using for loop

STEP 5: Search for the positive numbers in a for loop as  if (Arr[i] >=0)

STEP 6: If true it is a positive number otherwise continue the loop

STEP 7:Print the positive numbers using fmt.Println()


GO Source Code

                                          package main
import "fmt"

func main() {
    var size, i int
    fmt.Print("Enter the array size = ")

    Arr := make([]int, size)

    fmt.Print("Enter the array items  = ")
    for i = 0; i < size; i++ {

    fmt.Print("\nThe Positive Numbers  = ")
    for i = 0; i < size; i++ {
        if Arr[i] >= 0 {
            fmt.Print(Arr[i], " ")


Enter the array size = 5
Enter the array items  = -13 4 -9 0 15

The Positive Numbers  = 0 4 15