Go language program to take a number as input and tells its positive or negative

Views: 126   

Following program shows you how to take a number as input and tells its positive or negative.
In this program we get number from user, and if the number is less than zero it prints negative, and if the number is grater than zero it prints positive

package main

import "fmt"

func main() {

  var input int
  fmt.Println("Please enter a number:")
  fmt.Scanf("%d", &input)
  if (input < 0) {
  fmt.Println("Given number is -ve")
  } else {
  fmt.Println("Given number is +ve")
  }
}

Output:

Example1:

Please enter a number:
 18
Given number is +ve

Example2:

Please enter a number:
 -6
Given number is -ve
On By