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