Last active
December 24, 2017 22:06
-
-
Save ziadoz/2352ab855ba437d917551720ae52cb73 to your computer and use it in GitHub Desktop.
FizzBuzz in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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