How to find the Maximum of Three Numbers in Go - Step by Step Examples



How to find the Maximum of Three Numbers in Go ?

Answer

To find the maximum of three numbers in Go, you can use a simple comparison with if statements.



✐ Examples

1 Find Maximum of Three Numbers

In this example,

  1. We declare three variables a, b, and c with the numbers to compare.
  2. We use a series of if statements to compare the numbers and update the maximum accordingly.

Go Program

package main
import (
    "fmt"
)
func main() {
    a := 5
    b := 8
    c := 3
    max := a
    if b > max {
        max = b
    }
    if c > max {
        max = c
    }
    fmt.Printf("Maximum of three numbers is: %d\n", max)
}

Output

Maximum of three numbers is: 8

Summary

In this tutorial, we learned How to find the Maximum of Three Numbers in Go language with well detailed examples.




More Go Comparison Operations Tutorials

  1. How to find the Maximum of Two Numbers in Go ?
  2. How to find the Minimum of Two Numbers in Go ?
  3. How to find the Maximum of Three Numbers in Go ?
  4. How to find the Minimum of Three Numbers in Go ?