File tree Expand file tree Collapse file tree 1 file changed +72
-0
lines changed
content/go/concepts/math-functions/terms/max Expand file tree Collapse file tree 1 file changed +72
-0
lines changed Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments