Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. // fizzBuzz: any number divisible by 3 is Fizz and any number divisible by 5 is Buzz and both is FizzBuzz.
  2. func fizzBuzz(n int) string {
  3. var buf bytes.Buffer
  4.  
  5. for i := 1; i <= n; i++ {
  6. if i%15 == 0 {
  7. fmt.Fprintln(&buf, "Fizz Buzz")
  8. } else if i%3 == 0 {
  9. fmt.Fprintln(&buf, "Fizz")
  10. } else if i%5 == 0 {
  11. fmt.Fprintln(&buf, "Buzz")
  12. } else {
  13. fmt.Fprintln(&buf, i)
  14. }
  15. }
  16. return buf.String()
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement