Write a Go program to print the hollow right pascals triangle star pattern using for loop.
package main import "fmt" func main() { var i, j, row int fmt.Print("Enter Hollow Right Pascals Star Pattern Rows = ") fmt.Scanln(&row) fmt.Println("Hollow Right Pascals Star Triangle Pattern") for i = 1; i <= row; i++ { for j = 1; j <= i; j++ { if j == 1 || j == i { fmt.Printf("*") } else { fmt.Printf(" ") } } fmt.Println() } for i = 1; i <= row-1; i++ { for j = row - 1; j >= i; j-- { if j == row-1 || j == i || i == row { fmt.Printf("*") } else { fmt.Printf(" ") } } fmt.Println() } }
This Go example prints the hollow 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 Hollow Right Pascals Star Pattern Rows = ") fmt.Scanln(&row) fmt.Print("Character to Print in Hollow Right Pascals Triangle = ") ch, _, _ := reader.ReadRune() fmt.Println("Hollow Right Pascals Star Triangle Pattern") for i = 1; i <= row; i++ { for j = 1; j <= i; j++ { if j == 1 || j == i { fmt.Printf("%c", ch) } else { fmt.Printf(" ") } } fmt.Println() } for i = 1; i <= row-1; i++ { for j = row - 1; j >= i; j-- { if j == row-1 || j == i || i == row { fmt.Printf("%c", ch) } else { fmt.Printf(" ") } } fmt.Println() } }
Enter Hollow Right Pascals Star Pattern Rows = 14
Character to Print in Hollow Right Pascals Triangle = $
Hollow Right Pascals Star Triangle Pattern
$
$$
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$$
$