Skip to content

Instantly share code, notes, and snippets.

@otobrglez
Last active August 29, 2015 14:06
Show Gist options
  • Save otobrglez/d1fb760f1aca5fb57f41 to your computer and use it in GitHub Desktop.
Save otobrglez/d1fb760f1aca5fb57f41 to your computer and use it in GitHub Desktop.
FizzBuzz in C# with Mono for Friday
/*
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));
}
}
.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