Skip to content

Instantly share code, notes, and snippets.

@chandler767
Last active February 2, 2018 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chandler767/c818cc3c715dd9c9c48cfd24b1835a1d to your computer and use it in GitHub Desktop.
Save chandler767/c818cc3c715dd9c9c48cfd24b1835a1d to your computer and use it in GitHub Desktop.
Write a program that prints numbers from 1 to N. But for multiples of three print “Fizz” instead of the number, and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz".
package main
import "fmt"
func main() {
n := 15
for i:=1; i<=n; i++ {
if (i%3 == 0) && (i%5 == 0) {
fmt.Println("FizzBuzz")
} else if i%3 == 0 {
fmt.Println("Fizz")
} else if i%5 == 0 {
fmt.Println("Buzz")
} else {
fmt.Println(i)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment