Go Program to Print Star Pyramid Pattern

Write a Go Program to Print Star Pyramid Pattern. In this Golang Star Pyramid example, the first for loop iterates from start to row end. The second for loop (for j = 1; j <= rows-i; j++) iterates from 1 to rows-i and prints the empty spaces. The third for loop (for k := 0; k != (2*i – 1); k++) iterates from 0 to 2 multiplies i minus one and print star.

package main

import "fmt"

func main() {

    var i, j, rows int

    fmt.Print("Rows to Print the Star Pyramid = ")
    fmt.Scanln(&rows)

    fmt.Println("\nStar Pyramid Pattern")
    for i = 1; i <= rows; i++ {
        for j = 1; j <= rows-i; j++ {
            fmt.Print(" ")
        }
        for k := 0; k != (2*i - 1); k++ {
            fmt.Print("*")
        }
        fmt.Println()
    }
}
Go Program to Print Star Pyramid 1

This Golang program allows entering a symbol and prints the pyramid pattern of that symbol.

package main

import "fmt"

func main() {

    var i, j, rows int
    var sym string

    fmt.Print("Rows to Print the Star Pyramid = ")
    fmt.Scanln(&rows)

    fmt.Print("Symbol to Print as the Star Pyramid = ")
    fmt.Scanln(&sym)

    fmt.Println("\nPyramid Pattern of Given Symbol")
    for i = 1; i <= rows; i++ {
        for j = 1; j <= rows-i; j++ {
            fmt.Print(" ")
        }
        for k := 0; k != (2*i - 1); k++ {
            fmt.Printf("%s", sym)
        }
        fmt.Println()
    }
}
Rows to Print the Star Pyramid = 10
Symbol to Print as the Star Pyramid = $

Pyramid Pattern of Given Symbol
         $
        $$$
       $$$$$
      $$$$$$$
     $$$$$$$$$
    $$$$$$$$$$$
   $$$$$$$$$$$$$
  $$$$$$$$$$$$$$$
 $$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$