Write a Go program to print the left pascals star triangle using for loop.
package main import "fmt" func main() { var i, j, k, row int fmt.Print("Enter Left Pascals Star Pattern Rows = ") fmt.Scanln(&row) fmt.Println("Left Pascals Star Triangle Pattern") for i = 1; i <= row; i++ { for j = i; j < row; j++ { fmt.Printf(" ") } for k = 1; k <= i; k++ { fmt.Printf("* ") } fmt.Println() } for i = row; i >= 1; i-- { for j = i; j <= row; j++ { fmt.Printf(" ") } for k = 1; k < i; k++ { fmt.Printf("* ") } fmt.Println() } }
This Go example prints the left pascals triangle pattern of a given character.
package main import ( "bufio" "fmt" "os" ) func main() { reader := bufio.NewReader(os.Stdin) var i, j, k, row int fmt.Print("Enter Left Pascals Star Pattern Rows = ") fmt.Scanln(&row) fmt.Print("Character to Print in Left Pascals Triangle = ") ch, _, _ := reader.ReadRune() fmt.Println("Left Pascals Star Triangle Pattern") for i = 1; i <= row; i++ { for j = i; j < row; j++ { fmt.Printf(" ") } for k = 1; k <= i; k++ { fmt.Printf("%c ", ch) } fmt.Println() } for i = row; i >= 1; i-- { for j = i; j <= row; j++ { fmt.Printf(" ") } for k = 1; k < i; k++ { fmt.Printf("%c ", ch) } fmt.Println() } }
Enter Left Pascals Star Pattern Rows = 12
Character to Print in Left Pascals Triangle = @
Left Pascals Star Triangle Pattern
@
@ @
@ @ @
@ @ @ @
@ @ @ @ @
@ @ @ @ @ @
@ @ @ @ @ @ @
@ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @
@ @ @ @ @ @ @
@ @ @ @ @ @
@ @ @ @ @
@ @ @ @
@ @ @
@ @
@