Go Program to find the largest of three numbers using nested if


In this program, you will learn how to find the largest of three numbers using nested if statement in Go.


10 20 30 => 30

10 20 12 => 20

Example: How to find the largest of three numbers using nested if statement in Go

package main
import "fmt"

func main() {

	var x, y, z int
	fmt.Print("Enter three numbers:")
	fmt.Scan(&x, &y, &z)

	if x > y {
		if x > z {
			fmt.Println("Largest is:", x)
		} else {
			fmt.Println("Largest is:", z)
		}
	} else {
		if y > z {
			fmt.Println("Largest is:", y)
		} else {
			fmt.Println("Largest is:", z)
		}
	}
}

Output:

Enter three numbers:20 10 30                                                                                                           
Largest is: 30