Go Program to check a number is even or odd


In this program, you will learn how to check a number is even or odd in Go.


if num % 2 == 0 { 
    //statement 
}

Example: How to check a number is even or odd in Go

package main
import "fmt"

func main() {
	var num int
	fmt.Print("Enter a number:")
	fmt.Scan(&num)

	if num%2 == 0 {
		fmt.Println("Number is even:", num)
	} else {
		fmt.Println("Number is odd:", num)
	}
}

Output:

Enter a number:40
Number is even: 40