Go if statement Question 1 Fizz Buzz

Introduction

Program that prints numbers 1 through 100.

Replaces multiples of 3 with "Fizz," multiples of 5 with "Buzz," and multiples of both 3 and 5 with "FizzBuzz":

package main 

import "fmt" 

func main() { 
  for i  := 1; i <= 100; i++ { 
     // your code here
  } 
} 


package main 

import "fmt" 

func main() { 
  for i  := 1; i <= 100; 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) 
         } 
  } 
} 



PreviousNext

Related