Skip to content

Commit 93657a0

Browse files
Manikanta528SSwiniarskicaupolicandiaz
authored
[Term Entry] Go Math Function Max() (#2602)
* [Term Entry] Go Math Function Max() * review edits --------- Co-authored-by: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com> Co-authored-by: Caupolican Diaz <caupolicandiaz@gmail.com>
1 parent 801df77 commit 93657a0

File tree

1 file changed

+72
-0
lines changed
  • content/go/concepts/math-functions/terms/max

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
Title: 'Max()'
3+
Description: 'Returns the maximum value of two specified numbers.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Numbers'
9+
- 'Arithmetic'
10+
- 'Functions'
11+
CatalogContent:
12+
- 'learn-go'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`Max()`** function returns the maximum value of two specified numbers.
17+
18+
## Syntax
19+
20+
```pseudo
21+
import "math"
22+
23+
result := math.Max(num1, num2)
24+
```
25+
26+
`math.Max()` returns the maximum value from `num1` and `num2`.
27+
28+
## Example
29+
30+
The following example compares two integer values and prints out the maximum value `result`.
31+
32+
```go
33+
package main
34+
35+
import (
36+
"fmt"
37+
"math"
38+
)
39+
40+
func main() {
41+
result := math.Max(27, 28)
42+
fmt.Printf("%.1f\n", result)
43+
}
44+
```
45+
46+
The output will be:
47+
48+
```shell
49+
28.0
50+
```
51+
52+
## Codebyte Example
53+
54+
The following example is runnable and uses the `math.Max()` method to return the maximum value from the two given numbers.
55+
56+
```codebyte/golang
57+
package main
58+
59+
import (
60+
"fmt"
61+
"math"
62+
)
63+
64+
func main() {
65+
num1 := 800.0
66+
num2 := 700.0
67+
68+
result := math.Max(num1, num2)
69+
70+
fmt.Printf("The max value of %.1f and %.1f is %.1f\n", num1, num2, result)
71+
}
72+
```

0 commit comments

Comments
 (0)