Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

fizzbuzz

Examples

  • Python
def fizzbuzz(n):
    for i in range(1, n + 1):
        if i % 3 == 0 and i % 5 == 0:
            print('FizzBuzz')
        elif i % 3 == 0:
            print('Fizz')
        elif i % 5 == 0:
            print('Buzz')
        else:
            print(i)
  • Go
package main

import "fmt"

func main() {
    for i := 1; i <= 100; i++ {
        if i%3 == 0 {
            fmt.Printf("fizz")
        }
        if i%5 == 0 {
            fmt.Printf("buzz")
        }
        if i%3 != 0 && i%5 != 0 {
            fmt.Printf("%d", i)
        }
        fmt.Printf("\n")
    }
}
  • c#
for (int i = 1; i <= 100; i++)  
{  
    if (i % 3 == 0 && i % 5 == 0)  
    {  
        Console.WriteLine("FizzBuzz");  
    }  
    else if (i % 3 == 0)  
    {  
       Console.WriteLine("Fizz");  
    }  
    else if (i % 5 == 0)  
    {  
       Console.WriteLine("Buzz");  
    }  
    else  
    {  
        Console.WriteLine(i);  
    }  
}