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
Naming Conventions for Golang Functions
Program in Go language to Calculate Standard Deviation using Math package
How do you handle HTTP server health checks in Go?
How to print string with double quote in Go?
Exploring Blockchain: Top 15 Real-World Use Cases in 2024
How to convert Boolean Type to String in Go?