package main import "fmt" /*无返回值*/ func Sub1(a, b int) { ret := a - b fmt.Println("a-b=",ret) } /* 有返回值 返回值 int类型,参数a-b的结果 */ func Sub2(a,b int) int { ret := a-b return ret } func Sub3(a,b int) (difference int) { ret := a-b return ret } /* 多个返回值 计算两个数的和差积商 返回值 int,int,int,int 两个数的和差积商 */ func Calculate(a, b int) (sum int,difference int,product int,quotient float64) { sum = a + b difference = a - b product = a * b quotient = float64(a) /float64(b) return sum, difference, product, quotient } func main() { //Sub1(5,3) //ret := Sub2(5, 3) //fmt.Println(ret) //ret = Sub3(5, 5) //fmt.Println(ret) sum, difference, product, quotient := Calculate(3, 5) fmt.Println(sum, difference, product, quotient) }