practice/go/fizzbuzz/main.go

47 lines
867 B
Go

package main
/*Fizz buzz
Fiz on divisable on 3, buzz on divisable on 5, and fizbuzz if divisiable by both.
*/
import "fmt"
func main() {
//For Version
/* for num := 1; num < 101; num++ {
if num%3 == 0 && num%5 != 0 {
fmt.Println(num, " ", "fizz")
} else if (num%5 == 0) && (num%3 != 0) {
fmt.Println(num, " ", "buzz")
} else if num%5 == 0 && num%3 == 0 {
fmt.Println(num, " ", "fizzbuzz!!!")
} else {
fmt.Println(num)
}
}
*/
//recursive version
fizzBuzz(1, 100)
}
func fizzBuzz(small, big int) {
if small > big {
return
}
if small%3 == 0 && small%5 != 0 {
fmt.Println(small, " ", "fizz")
} else if (small%5 == 0) && (small%3 != 0) {
fmt.Println(small, " ", "buzz")
} else if small%5 == 0 && small%3 == 0 {
fmt.Println(small, " ", "fizzbuzz!!!")
} else {
fmt.Println(small)
}
fizzBuzz(small+1, big)
}