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
How to use WaitGroup to delay execution of the main function until after all goroutines are complete.
Launches 10 Goroutines and each goroutine adding 10 values to a Channel
Go program to find SRV service record of a domain
Interfaces with similar methods in Go Programming Language
Example of Sscan vs Sscanf vs Sscanln from FMT Package
Illustration of the dining philosophers problem in Golang