Go language program to take a number as input and tells its even or odd number

Views: 114   

Following program shows you how to take a number as input and tells its even or odd number.
This program divides input by 2, If remainder is zero it prints even otherwise it prints odd

package main

import "fmt"

func main() {

  var input int
  fmt.Println("Please enter a number:")
  fmt.Scanf("%d", &input)
  if (input % 2 == 0) {
    fmt.Println("even")
  } else {
    fmt.Println("odd")
  }
}

Output:

Example1:

Please enter a number:
 18
even

Example2:

Please enter a number:
 21
odd
On By