Write a program , Output from 1 reach n String representation of numbers .
1. If n yes 3 Multiple of , output “Fizz”;
2. If n yes 5 Multiple of , output “Buzz”;
3. If n At the same time 3 and 5 Multiple of , output “FizzBuzz”.
Examples :
input :15
output :["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
func fizzBuzz(n int) []string { s := []string{} for i:=1; i<=n ;i++{ if i%3 ==0
&& i % 5 == 0 { s = append(s,"FizzBuzz") }else if i%3 ==0 { s =
append(s,"Fizz") }else if i%5 == 0{ s = append(s,"Buzz") }else { s =
append(s,strconv.Itoa(i)) } } return s }
Key points of problem solving :int turn string use strconve.Itoa(i) function
Technology
Daily Recommendation