fizzbuzz in golang code example
Example 1: fizzbuzz golang
func fizzBuzz(n int32) {
var i int32
var output string
for i= 1;i <= n; i++{
output = ""
if i %3 == 0 {
output += "Fizz"
}
if i %5 == 0 {
output += "Buzz"
}
if output == ""{
output = fmt.Sprintf("%d", i)
}
fmt.Println(output)
}
}
Example 2: go fizzbuzz
import "fmt"
func main() {
for i := 1; i <= 100; i++ {
s := ""
if i%3==0 {
s = "Fizz"
}
if i%5==0 {
s = "Buzz"
}
if s == "" {
s = fmt.Sprintf("%d", i)
}
fmt.Printf("%s\n", s)
}
}