diff --git a/challenges/fizzbuzz/solutions/cs/function/README.md b/challenges/fizzbuzz/solutions/cs/function/README.md new file mode 100644 index 0000000..b595104 --- /dev/null +++ b/challenges/fizzbuzz/solutions/cs/function/README.md @@ -0,0 +1,3 @@ +# fizzbuzz/cs/function + +Created by [@Divlo](https://github.com/Divlo) on 10 September 2021. diff --git a/challenges/fizzbuzz/solutions/cs/function/Solution.cs b/challenges/fizzbuzz/solutions/cs/function/Solution.cs new file mode 100644 index 0000000..a097bcb --- /dev/null +++ b/challenges/fizzbuzz/solutions/cs/function/Solution.cs @@ -0,0 +1,33 @@ +using System; + +namespace Solution +{ + class Program + { + static void Main() + { + int total = int.Parse(Console.ReadLine()); + for (int number = 1; number <= total; number++) + { + bool isDivisibleBy3 = number % 3 == 0; + bool isDivisibleBy5 = number % 5 == 0; + if (isDivisibleBy3 && isDivisibleBy5) + { + Console.WriteLine("FizzBuzz"); + } + else if (isDivisibleBy3) + { + Console.WriteLine("Fizz"); + } + else if (isDivisibleBy5) + { + Console.WriteLine("Buzz"); + } + else + { + Console.WriteLine(number); + } + } + } + } +}