SHARE
TWEET

Untitled

a guest Feb 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top