Golang Program to print numbers with diamond pattern
Example
package main
import "fmt"
func main() {
rows := 9
space := rows / 2
num := 1
for i := 1; i <= rows; i++ {
for j := 1; j <= space; j++ {
fmt.Printf(" ")
}
count := num/2 + 1
for k := 1; k <= num; k++ {
fmt.Printf("%d", count)
if k <= num/2 {
count--
} else {
count++
}
}
fmt.Println()
if i <= rows/2 {
space = space - 1
num = num + 2
} else {
space = space + 1
num = num - 2
}
}
}
Output
1
212
32123
4321234
543212345
4321234
32123
212
1
Most Helpful This Week
Example of Fscan, Fscanf, and Fscanln from FMT Package
Golang write CSV records
Golang program for implementation of AVL Trees
Empowering Developers: Google Cloud’s Generative AI Systems
Example: How to use ReadAtLeast from IO Package in Golang?
How do you set headers in an HTTP response in Go?
Nested Struct Type
Goroutines Channels order of execution
3 Different Examples - How State Works in React?
How to Iterate Over a Slice in Golang?