Write a Go Program to Print Square Star Pattern. In this Golang Square Star pattern example, the nested for loop iterates Square sides. Within the loop, we print stars in square shape.
package main import "fmt" func main() { var i, j, side int fmt.Print("Enter Any Side of a Square = ") fmt.Scanln(&side) fmt.Println("Square Star Pattern") for i = 0; i < side; i++ { for j = 0; j < side; j++ { fmt.Print("* ") } fmt.Println() } }
This Go program allows entering any symbol and prints the Square pattern with that symbol.
package main import "fmt" func main() { var i, j, side int var ch string fmt.Print("Enter Any Side of a Square = ") fmt.Scanln(&side) fmt.Print("Symbol to Print the Square Pattern = ") fmt.Scanln(&ch) fmt.Println("Square Star Pattern") for i = 0; i < side; i++ { for j = 0; j < side; j++ { fmt.Printf("%s ", ch) } fmt.Println() } }
Enter Any Side of a Square = 10
Symbol to Print the Square Pattern = $
Square Star Pattern
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $
$ $ $ $ $ $ $ $ $ $