Skip to content

Instantly share code, notes, and snippets.

@valeriofarias
Created December 27, 2015 20:42
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 valeriofarias/cf20a51dd64613a240c6 to your computer and use it in GitHub Desktop.
Save valeriofarias/cf20a51dd64613a240c6 to your computer and use it in GitHub Desktop.
FizzBuzz written using Golang
// FizzBuzz
// A program that prints the 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"
"strconv"
)
func main(){
for i := 1 ; i < 100 ; i++ {
var name string = ""
if i % 3 == 0 { name = "Fizz" }
if i % 5 == 0 { name += "Buzz" }
if name == "" { name = strconv.Itoa(i) }
fmt.Print("| " + name + " ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment