-
-
Save EricBeales/4503615 to your computer and use it in GitHub Desktop.
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; | |
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(""); | |
} | |
} | |
} | |
} |
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
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.