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