初始化
This commit is contained in:
3
01_basics/03_operators/go.mod
Normal file
3
01_basics/03_operators/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module operators
|
||||
|
||||
go 1.23.5
|
29
01_basics/03_operators/main.go
Normal file
29
01_basics/03_operators/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
a, b := 15, 10
|
||||
|
||||
// 算术运算符
|
||||
sum := a + b
|
||||
diff := a - b
|
||||
product := a * b
|
||||
quotient := a / b
|
||||
remainder := a % b
|
||||
|
||||
// 比较运算符
|
||||
eq := a == b
|
||||
gt := a > b
|
||||
lt := a < b
|
||||
|
||||
fmt.Println("运算符示例:")
|
||||
fmt.Printf("%d + %d = %d\n", a, b, sum)
|
||||
fmt.Printf("%d - %d = %d\n", a, b, diff)
|
||||
fmt.Printf("%d * %d = %d\n", a, b, product)
|
||||
fmt.Printf("%d / %d = %d\n", a, b, quotient)
|
||||
fmt.Printf("%d %% %d = %d\n", a, b, remainder)
|
||||
fmt.Printf("%d == %d: %t\n", a, b, eq)
|
||||
fmt.Printf("%d > %d: %t\n", a, b, gt)
|
||||
fmt.Printf("%d < %d: %t\n", a, b, lt)
|
||||
}
|
Reference in New Issue
Block a user