Pascal triangle in Go Programming Language
Example
package main
import "fmt"
func main() {
var rows, temp = 7, 1
for i := 0; i < rows; i++ {
for j := 1; j <= rows-i; j++ {
fmt.Print(" ")
}
for k := 0; k <= i; k++ {
if k == 0 || i == 0 {
temp = 1
} else {
temp = temp * (i - k + 1) / k
}
fmt.Printf(" %d", temp)
}
fmt.Println("")
}
}
Output
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
Most Helpful This Week
How do you set headers in an HTTP response in Go?
How do you read cookies in an HTTP request with an HTTP client in Go?
Contains, ContainsAny, Count and EqualFold string functions in Go Language
State and Props in React
How to check if an item exists in Slice in Golang?
Interface Accepting Address of the Variable in Golang
How to create Slice of Struct in Golang?
How to set timeout for http.Get() requests in Golang?
How to Convert string to float type in Go?
Golang write CSV records