Go program to Print Sandglass Star Pattern

Write a Go program to print the sandglass star pattern using for loop. 

package main

import "fmt"

func main() {

	var i, j, k, row int

	fmt.Print("Enter Sandglass Star Pattern Rows = ")
	fmt.Scanln(&row)

	fmt.Println("**** Sandglass Star Pattern ****")

	for i = 0; i <= row-1; i++ {
		for j = 0; j < i; j++ {
			fmt.Printf(" ")
		}
		for k = i; k <= row-1; k++ {
			fmt.Printf("* ")
		}
		fmt.Println()
	}

	for i = row - 1; i >= 0; i-- {
		for j = 0; j < i; j++ {
			fmt.Printf(" ")
		}
		for k = i; k <= row-1; k++ {
			fmt.Printf("* ")
		}
		fmt.Println()
	}
}
Go program to Print Sandglass Star Pattern

This Go example prints the sandglass 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 Sandglass Star Pattern Rows = ")
	fmt.Scanln(&row)

	fmt.Print("Enter Character to Print in Sandglass = ")
	ch, _, _ := reader.ReadRune()

	fmt.Println("**** Sandglass Star Pattern ****")

	for i = 0; i <= row-1; i++ {
		for j = 0; j < i; j++ {
			fmt.Printf(" ")
		}
		for k = i; k <= row-1; k++ {
			fmt.Printf("%c ", ch)
		}
		fmt.Println()
	}

	for i = row - 1; i >= 0; i-- {
		for j = 0; j < i; j++ {
			fmt.Printf(" ")
		}
		for k = i; k <= row-1; k++ {
			fmt.Printf("%c ", ch)
		}
		fmt.Println()
	}
}
Enter Sandglass Star Pattern Rows = 10
Enter Character to Print in Sandglass = $
**** Sandglass 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.