Menu Close

Go – How to get maximum between two numbers in go

Here, We will learn how to get maximum between two numbers in go. We can get it by using Max() function in math package in go golang.

Function prototype:

func Max(x, y float64) float64

Input parameters: x and y as float64

Return value:

Max() function in math package returns
maximum between two numbers

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.Max(1.2, 3)
  fmt.Println(no)

  no = math.Max(2.3, 1)
  fmt.Println(no)

  no = math.Max(0.0, -3)
  fmt.Println(no)

  no = math.Max(-2.9, 10)
  fmt.Println(no)
}

Output:

3
2.3
0
10

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, math

Leave a Reply

Your email address will not be published. Required fields are marked *