FizzBuzz problem in Go

Udit Saurabh
1 min readJul 12, 2022

--

Requirements

  • Print Integer 1 to 50, except:
  1. Print “Fizz” if the number is divisible by 3.
  2. Print “Buzz” if the number is divisible by 5.
  3. Print “FizzBuzz” if the number is divisible by 3 and 5.

ideally, we should write the logic for the lcm of two numbers

but since its already given 3,5

so I directly used their lcm.

Also, we are placing this logic at the top

because “fizz” and “buzz” will both execute if we place it lower.

//fizzBuzz problems

func fizzBuzzProblem() {

for i := 1; i <= 50; i++ {

if i%15 == 0 {

/*

ideally we should write logic for the lcm of two numbers

but since its already given 3,5

so i directly used their lcm.

Also we are placing this logic at the top

because “fizz” and “buzz” will both execute if we place it lower.

*/

fmt.Println(“FizzBuzz”)

} else if i%3 == 0 {

fmt.Println(“Fizz”)

} else if i%5 == 0 {

fmt.Println(“Buzz”)

} else {

fmt.Println(i)

}

}

}

Fizz buzz implementation in other programming language is as follows.

Geeks for Geeks link for fizzbuzz

--

--

Udit Saurabh

full-stack developer, problem solver, technical writer