mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
feat(solutions): add fizzbuzz/cs/function
This commit is contained in:
parent
43fe49a5be
commit
a1f20afb36
3
challenges/fizzbuzz/solutions/cs/function/README.md
Normal file
3
challenges/fizzbuzz/solutions/cs/function/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# fizzbuzz/cs/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 10 September 2021.
|
33
challenges/fizzbuzz/solutions/cs/function/Solution.cs
Normal file
33
challenges/fizzbuzz/solutions/cs/function/Solution.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user