update book code

This commit is contained in:
Unknwon
2015-03-03 12:25:25 -05:00
parent b8c82ba4e5
commit eab1d98ba8
465 changed files with 15392 additions and 1572 deletions

View File

@@ -0,0 +1,39 @@
// Q13_1_max.go
package main
import (
"fmt"
"math"
)
func main() {
sl1 := []int{78,34,643,12,90,492, 13, 2}
max := maxSlice(sl1)
fmt.Printf("The maximum is %d\n", max)
min := minSlice(sl1)
fmt.Printf("The minimum is %d\n", min)
}
func maxSlice(sl []int) (max int) {
for _, v := range sl {
if v > max {
max = v
}
}
return
}
func minSlice(sl [] int) (min int) {
// min = int(^uint(0) >> 1)
min = math.MaxInt32
for _, v := range sl {
if v < min {
min = v
}
}
return
}
/* Output:
The maximum is 643
The minimum is 2
*/