FizzBuzz C# implementation

public void Fizzbuzz()
{
for (int i = 1; i <= 100; i++)
{
bool fizz = i % 3 == 0;
bool buzz = i % 5 == 0;
if (fizz && buzz)
Console.WriteLine("FizzBuzz");
else if (fizz)
Console.WriteLine("Fizz");
else if (buzz)
Console.WriteLine("Buzz");
else
Console.WriteLine(i);
}
}

One of the more popular whiteboard questions

Leave a Reply

Your email address will not be published. Required fields are marked *