Created
December 27, 2015 20:42
-
-
Save valeriofarias/cf20a51dd64613a240c6 to your computer and use it in GitHub Desktop.
FizzBuzz written using Golang
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
// 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