Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Last active December 24, 2017 22:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziadoz/2352ab855ba437d917551720ae52cb73 to your computer and use it in GitHub Desktop.
Save ziadoz/2352ab855ba437d917551720ae52cb73 to your computer and use it in GitHub Desktop.
FizzBuzz in Go
package main
import "fmt"
const (
FIZZ = 3
BUZZ = 5
FIZZBUZZ = 15
)
func main() {
for i := 0; i <= 100; i++ {
result := fizzbuzz(i)
fmt.Printf("%v %s\n", i, result)
}
}
func fizzbuzz(num int) (str string) {
switch {
case num == 0:
str += ""
case num%FIZZBUZZ == 0:
str += "FizzBuzz"
case num%FIZZ == 0:
str += "Fizz"
case num%BUZZ == 0:
str += "Buzz"
}
return str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment