Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // fizzBuzz: any number divisible by 3 is Fizz and any number divisible by 5 is Buzz and both is FizzBuzz.
- func fizzBuzz(n int) string {
- var buf bytes.Buffer
- for i := 1; i <= n; i++ {
- if i%15 == 0 {
- fmt.Fprintln(&buf, "Fizz Buzz")
- } else if i%3 == 0 {
- fmt.Fprintln(&buf, "Fizz")
- } else if i%5 == 0 {
- fmt.Fprintln(&buf, "Buzz")
- } else {
- fmt.Fprintln(&buf, i)
- }
- }
- return buf.String()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement