Program to print pyramid using numbers
Example
package main
import "fmt"
func main() {
var rows, count, count1, k int = 5, 0, 0, 0
for i := 1; i <= rows; i++ {
k = 0
for space := 1; space <= rows-i; space++ {
fmt.Print(" ")
count++
}
for {
if k == 2*i-1 {
break
}
if count <= rows-1 {
fmt.Printf("%d ", i+k)
count++
} else {
count1++
fmt.Printf("%d ", (i + k - 2*count1))
}
k++
}
count1, k, count = 0, 0, 0
fmt.Println("")
}
}
Output
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
Most Helpful This Week
GO Program to Swap Number Without Using Temporary Variables
Nested Struct Type
Contains, ContainsAny, Count and EqualFold string functions in Go Language
Golang program for implementation of Floyd–Warshall Algorithm
Interface embedding another interface in Go Programming Language
GO Program to Check Armstrong Number