Write a Go Program to Print Inverted Right Angled Triangle Star Pattern. In this Golang Inverted Right Triangle Star example, the first loop iterates from end to start. The second one (for j = i; j > 0; j–) iterates from i to 0. Within the loop, we print stars.
package main import "fmt" func main() { var i, j, rows int fmt.Print("Rows to Print the Inverted Right Triangle = ") fmt.Scanln(&rows) fmt.Println("\nInverted Right Angled Triangle") for i = rows; i > 0; i-- { for j = i; j > 0; j-- { fmt.Print("* ") } fmt.Println() } }
This Golang program allows us to enter any symbol and prints the Inverted Right angled Triangle pattern of the given symbol.
package main import "fmt" func main() { var i, j, rows int var sym string fmt.Print("Rows to Print the Inverted Right Triangle = ") fmt.Scanln(&rows) fmt.Print("Symbol to Print as Inverted Right Triangle = ") fmt.Scanln(&sym) fmt.Println("\nInverted Right Angled Triangle") for i = rows; i > 0; i-- { for j = i; j > 0; j-- { fmt.Printf("%s ", sym) } fmt.Println() } }
Rows to Print the Inverted Right Triangle = 11
Symbol to Print as Inverted Right Triangle = @
Inverted Right Angled Triangle
@ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @
@ @ @ @ @ @ @
@ @ @ @ @ @
@ @ @ @ @
@ @ @ @
@ @ @
@ @
@