Go Program to Print Right Pascals Star Triangle

Write a Go program to print the right pascals star triangle using for loop. 

package main

import "fmt"

func main() {

	var i, j, row int

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

	fmt.Println("Right Pascals Star Triangle Pattern")

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

	for i = row - 1; i >= 0; i-- {
		for j = 0; j <= i-1; j++ {
			fmt.Printf("* ")
		}
		fmt.Println()
	}
}
Go Program to Print Right Pascals Star Triangle

This Go example prints the right pascals triangle pattern of a given character.

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	reader := bufio.NewReader(os.Stdin)

	var i, j, row int

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

	fmt.Print("Character to Print in Right Pascals Triangle = ")
	ch, _, _ := reader.ReadRune()

	fmt.Println("Right Pascals Star Triangle Pattern")

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

	for i = row - 1; i >= 0; i-- {
		for j = 0; j <= i-1; j++ {
			fmt.Printf("%c ", ch)
		}
		fmt.Println()
	}
}
Enter Right Pascals Star Pattern Rows = 12
Character to Print in Right Pascals Triangle = @
Right Pascals Star Triangle 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.