Created
April 12, 2024 11:43
-
-
Save xeptore/bf5cc81abeb8c47a10bbf7e6f3251d88 to your computer and use it in GitHub Desktop.
Fizzbuzz in Go
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
package main | |
import ( | |
"fmt" | |
"strconv" | |
) | |
func main() { | |
var iterationsStr string | |
fmt.Print("Enter the number of iterations: ") | |
fmt.Scanln(&iterationsStr) | |
iterations, err := strconv.Atoi(iterationsStr) | |
if err != nil { | |
fmt.Println("Invalid input. Please enter a valid number.") | |
return | |
} | |
for i := 1; i <= iterations; i++ { | |
if i%3 == 0 && i%5 == 0 { | |
fmt.Println("FizzBuzz") | |
} else if i%3 == 0 { | |
fmt.Println("Fizz") | |
} else if i%5 == 0 { | |
fmt.Println("Buzz") | |
} else { | |
fmt.Println(i) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can be run using:
Of course needs Go installed, and being available.