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