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
How to add items to Slice using append function in Golang?
How to Convert string to integer type in Go?
Explain in Brief Golang error handling best practices
GO Program to Swap Number Without Using Temporary Variables
Golang program for implementation of AVL Trees
Golang program to print a matrix in Spiral Format
Multiple-value <function> in single-value context error in Golang
How to slice elements in Golang?
How to declare Interface Type in Go Programming Language
Cannot use <variable> (type <type>) as type <new-type> error in Golang