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