Skip to content

Instantly share code, notes, and snippets.

@EricBeales
Forked from Pharylon/gist:4502183
Last active December 10, 2015 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricBeales/4503615 to your computer and use it in GitHub Desktop.
Save EricBeales/4503615 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Count up from 1 to 100.
for (int i = 1; i <= 100; i++)
{
// If a number is not a multiple of 3 or 5, print it.
if (((i % 3) != 0) && ((i % 5) != 0))
{
Console.Write(i);
}
else
{
// If a number is a multiple of 3 print "Fizz"
if ((i % 3) == 0)
{
Console.Write("Fizz");
}
// If a number is a multiple of 5 print "Buzz"
if((i % 5) == 0)
{
Console.Write("Buzz");
}
}
// Print a new line between numbers.
Console.WriteLine("");
}
}
}
}
@dialalpha
Copy link

This is not a valid C# program. Neither i%3 nor i%5 evaluate to boolean expressions.
Also, seems like your program would actually print the opposite of the requirements of the FizzBuzz spec if you fix the syntax errors.

@EricBeales
Copy link
Author

Nice catch on the syntax error. I didn't realize C# was different than C in evaluating integers as bool's. As far as meeting the fizzbuzz spec though, as far as I can tell it is correct. =/

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