-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.