杨辉三角形 Posted on 2018-07-05 | 杨辉三角形 123456789101112131415161718192021222324252627282930313233package mainimport "fmt"//行数const LINES int = 10// 杨辉三角func ShowYangHuiTriangle() { nums := []int{} for i := 0; i < LINES; i++ { //补空白 for j := 0; j < (LINES - i); j++ { fmt.Print(" ") } for j := 0; j < (i + 1); j++ { var length = len(nums) var value int if j == 0 || j == i { value = 1 } else { value = nums[length-i] + nums[length-i-1] } nums = append(nums, value) fmt.Print(value, " ") } fmt.Println("") }}func main() { ShowYangHuiTriangle()} 坚持技术分享,您的支持将鼓励我继续创作! Donate WeChat Pay