Go Program to Print Plus Star Pattern

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()
	}
}
Go Program to Print Plus Star Pattern

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
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
@@@@@@@@@@@@@@@@@@@@@@@@@
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 
            @ 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.