Skip to content

Instantly share code, notes, and snippets.

@xeptore
Created April 12, 2024 11:43
Show Gist options
  • Save xeptore/bf5cc81abeb8c47a10bbf7e6f3251d88 to your computer and use it in GitHub Desktop.
Save xeptore/bf5cc81abeb8c47a10bbf7e6f3251d88 to your computer and use it in GitHub Desktop.
Fizzbuzz in Go
package main
import (
"fmt"
"strconv"
)
func main() {
var iterationsStr string
fmt.Print("Enter the number of iterations: ")
fmt.Scanln(&iterationsStr)
iterations, err := strconv.Atoi(iterationsStr)
if err != nil {
fmt.Println("Invalid input. Please enter a valid number.")
return
}
for i := 1; i <= iterations; i++ {
if i%3 == 0 && i%5 == 0 {
fmt.Println("FizzBuzz")
} else if i%3 == 0 {
fmt.Println("Fizz")
} else if i%5 == 0 {
fmt.Println("Buzz")
} else {
fmt.Println(i)
}
}
}
@xeptore
Copy link
Author

xeptore commented Apr 12, 2024

Can be run using:

go run ./main.go

Of course needs Go installed, and being available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment