Thursday, January 1, 2015

FizzBuzz

This is a simple implementation of the FizzBuzz Test in Go.

package main
import "fmt"
func main() {
for i := 1; i <= 100; i++ {
if i%15 == 0 { //divisible by 5 and 3
fmt.Println("FizzBuzz")
} else if i%5 == 0 { //divisible by 5
fmt.Println("Buzz")
} else if i%3 == 0 { //divisible by 3
fmt.Println("Fizz")
} else { //not divisible by either 5 or 3
fmt.Printf("%d\n", i)
}
}
}
view raw FizzBuzz.go hosted with ❤ by GitHub

No comments:

Post a Comment