Go Program to Check Positive or Negative

Any number greater than zero is positive, and if it is less than zero, then the negative number. This Go program uses the If else to check the given number is Positive or Negative. If you see the If condition, it checks whether the user-given number is greater than zero.

package main

import "fmt"

func main() {

    var num int

    fmt.Print("Please enter any Integer = ")
    fmt.Scanf("%d", &num)

    if num >= 0 {
        fmt.Println("Positive Integer")
    } else {
        fmt.Println("Negative Integer")
    }
}
SureshMac:GoExamples suresh$ go run positiveNeg1.go
Please enter any Integer = 10
Positive Integer
SureshMac:GoExamples suresh$ go run positiveNeg1.go
Please enter any Integer = -89
Negative Integer
SureshMac:GoExamples suresh$ go run positiveNeg1.go
Please enter any Integer = 0
Positive Integer

Golang program to Check Positive or Negative

This Golang program uses the Nested If condition to check the zeros along with positive and numbers.

package main

import "fmt"

func main() {

    var num int

    fmt.Print("Please enter any Integer = ")
    fmt.Scanf("%d", &num)

    if num > 0 {
        fmt.Println("Positive Integer")
    } else if num < 0 {
        fmt.Println("Negative Integer")
    } else {
        fmt.Println("You have entered Zero")
    }
}
Go Program to Check Positive or Negative 2

In this Go Program, we used the Nested For loop to check the number is positive, negative, or zero.

package main

import "fmt"

func main() {

    var num int

    fmt.Print("Please enter any Integer = ")
    fmt.Scanf("%d", &num)

    if num >= 0 {
        if num > 0 {
            fmt.Println("Positive Integer")
        } else {
            fmt.Println("You have entered Zero")
        }

    } else {
        fmt.Println("Negative Integer")
    }
}
SureshMac:GoExamples suresh$ go run positiveNeg3.go
Please enter any Integer = -55
Negative Integer
SureshMac:GoExamples suresh$ go run positiveNeg3.go
Please enter any Integer = 0
You have entered Zero
SureshMac:GoExamples suresh$ go run positiveNeg3.go
Please enter any Integer = 2
Positive Integer