Pascal's Triangle

Print Pascal's triangle using nested loops.

package main

import "fmt"

func main() {
	rows := 6

	for i := 0; i < rows; i++ {
		for s := 0; s < rows-i-1; s++ {
			fmt.Print("  ")
		}

		val := 1
		for j := 0; j <= i; j++ {
			fmt.Printf("%4d", val)
			val = val * (i - j) / (j + 1)
		}
		fmt.Println()
	}
}
▶ Open Go Playground

Copy the code above and paste to run

© 2026 ByteLearn.dev. Free courses for developers. · Privacy