Last active
August 29, 2015 14:06
-
-
Save otobrglez/d1fb760f1aca5fb57f41 to your computer and use it in GitHub Desktop.
FizzBuzz in C# with Mono for Friday
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
/* | |
By Oto Brglez - <otobrglez@gmail.com> | |
What is FizzBuzz? http://en.wikipedia.org/wiki/Fizz_buzz | |
Requirements: Mono & Make | |
Compile with: make | |
Run with: mono ./FizzBuzz.exe | |
*/ | |
using System; | |
using System.Text; | |
public class FizzBuzz { | |
public String FizzBuzzFor(int i){ | |
StringBuilder stringBuilder = new StringBuilder(); | |
int c = 1; | |
String tmp = ""; | |
while(c < i){ | |
tmp = ""; | |
if (c % 3 == 0) tmp = String.Concat(tmp, "Fizz"); | |
if (c % 5 == 0) tmp = String.Concat(tmp, "Buzz"); | |
if (tmp.Equals("")) tmp = String.Concat(tmp, c); | |
tmp = String.Concat(tmp, " "); | |
stringBuilder.Append(tmp); | |
c = c + 1; | |
} | |
return stringBuilder.ToString(); | |
} | |
public static void Main(String[] args){ | |
FizzBuzz fizzBuzz = new FizzBuzz(); | |
System.Console.WriteLine(fizzBuzz.FizzBuzzFor(100)); | |
} | |
} |
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
.PHONY: FizzBuzz.cs | |
all: run | |
FizzBuzz.exe: FizzBuzz.cs | |
@gmcs FizzBuzz.cs | |
clean: | |
@rm -f FizzBuzz.exe | |
run: FizzBuzz.exe | |
@mono FizzBuzz.exe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment