go
This commit is contained in:
parent
02a0b20746
commit
c6cf452643
11
10-for.go
Normal file
11
10-for.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
i := 1
|
||||||
|
for i <= 10 {
|
||||||
|
fmt.Println(i)
|
||||||
|
i = i + 1
|
||||||
|
}
|
||||||
|
}
|
15
11-if.go
Normal file
15
11-if.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
i := 1
|
||||||
|
for i <= 10 {
|
||||||
|
if i % 2 == 0 {
|
||||||
|
fmt.Println("even")
|
||||||
|
} else {
|
||||||
|
fmt.Println("odd")
|
||||||
|
}
|
||||||
|
i = i + 1
|
||||||
|
}
|
||||||
|
}
|
10
12-arrays.go
Normal file
10
12-arrays.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var x [5]int
|
||||||
|
x[4] = 100
|
||||||
|
fmt.Println(x)
|
||||||
|
fmt.Println(x[4])
|
||||||
|
}
|
18
13-sum.go
Normal file
18
13-sum.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var x [5]float64
|
||||||
|
x[0] = 98
|
||||||
|
x[1] = 93
|
||||||
|
x[2] = 77
|
||||||
|
x[3] = 82
|
||||||
|
x[4] = 83
|
||||||
|
|
||||||
|
var total float64 = 0
|
||||||
|
for i := 0; i < 5; i++ {
|
||||||
|
total += x[i]
|
||||||
|
}
|
||||||
|
fmt.Println(total / float64(len(x)))
|
||||||
|
}
|
18
14-range.go
Normal file
18
14-range.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var x [5]float64
|
||||||
|
x[0] = 98
|
||||||
|
x[1] = 93
|
||||||
|
x[2] = 77
|
||||||
|
x[3] = 82
|
||||||
|
x[4] = 83
|
||||||
|
|
||||||
|
var total float64 = 0
|
||||||
|
for _, value := range x {
|
||||||
|
total += value
|
||||||
|
}
|
||||||
|
fmt.Println(total / float64(len(x)))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user