Last active
July 18, 2022 14:38
-
-
Save rnemeth90/063288d38cfc534e2c6c59a3b31107ef to your computer and use it in GitHub Desktop.
Go FizzBuzz
This file contains hidden or 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" | |
"strconv" | |
) | |
func fizzbuzz(num int) string { | |
switch { | |
case num%15 == 0: | |
return "FizzBuzz" | |
case num%3 == 0: | |
return "Fizz" | |
case num%5 == 0: | |
return "Buzz" | |
} | |
return strconv.Itoa(num) | |
} | |
func main() { | |
for num := 1; num <= 100; num++ { | |
fmt.Println(fizzbuzz(num)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment