Skip to content

Instantly share code, notes, and snippets.

@dialalpha
Forked from Pharylon/gist:4502183
Last active December 10, 2015 22:38
Show Gist options
  • Save dialalpha/4504024 to your computer and use it in GitHub Desktop.
Save dialalpha/4504024 to your computer and use it in GitHub Desktop.
FizzBuzz. Can be written in shorter lines of code. But I find this implementation to be clearer.
using System;
namespace Dialalpha.FizzBuzz
{
class Program
{
static void Main(string[] args)
{
bool fizz = false, buzz = false;
for (int i = 1; i <= 100; ++i)
{
fizz = (i % 3 == 0); // true if i is a multiple of 3
buzz = (i % 5 == 0); // true if i is a multiple of 5
if (fizz && buzz)
Console.WriteLine("FizzBuzz");
else if (fizz)
Console.WriteLine("Fizz");
else if (buzz)
Console.WriteLine("Buzz");
else Console.WriteLine(i);
}
}
}
}
@dialalpha
Copy link
Author

@EricBeales: I usually tend to initialize my booleans when I declare them just to be on the safe side. I'll edit to add some comments though. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment