Write a Go Program to Print Inverted Pyramid Star Pattern. In this Golang Inverted Star Pyramid example, the first for loop iterates from end to start. The second for loop (for j = 0; j <= rows-i; j++) iterates from 0 to rows-i and it prints the empty spaces. The third for loop (for k := 0; k < (2*i – 1); k++) iterates from 0 to 2 multiplies i minus one and print stars.
package main import "fmt" func main() { var i, j, rows int fmt.Print("Rows to Print the Inverted Star Pyramid = ") fmt.Scanln(&rows) fmt.Println("\nInverted Pyramid Star Pattern") for i = rows; i > 0; i-- { for j = 0; j <= rows-i; j++ { fmt.Print(" ") } for k := 0; k < (2*i - 1); k++ { fmt.Print("*") } fmt.Println() } }
This Golang program allows entering a symbol and prints the inverted pyramid pattern of that symbol.
package main import "fmt" func main() { var i, j, rows int var sym string fmt.Print("Rows to Print the Inverted Star Pyramid = ") fmt.Scanln(&rows) fmt.Print("Symbol to Print as the Inverted Pyramid = ") fmt.Scanln(&sym) fmt.Println("\nInverted Pyramid Pattern") for i = rows; i > 0; i-- { for j = 0; j <= rows-i; j++ { fmt.Print(" ") } for k := 0; k < (2*i - 1); k++ { fmt.Printf("%s", sym) } fmt.Println() } }
Rows to Print the Inverted Star Pyramid = 12
Symbol to Print as the Inverted Pyramid = $
Inverted Pyramid Pattern
$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$
$$$$$$$
$$$$$
$$$
$