From a1a0c65c162a693bdb189030b2f9c2dd722f07ca Mon Sep 17 00:00:00 2001 From: Divlo Date: Wed, 29 Sep 2021 10:15:08 +0200 Subject: [PATCH] feat(solutions): add `fizzbuzz/c/function` --- .../fizzbuzz/solutions/c/function/README.md | 3 +++ .../fizzbuzz/solutions/c/function/solution.c | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 challenges/fizzbuzz/solutions/c/function/README.md create mode 100644 challenges/fizzbuzz/solutions/c/function/solution.c diff --git a/challenges/fizzbuzz/solutions/c/function/README.md b/challenges/fizzbuzz/solutions/c/function/README.md new file mode 100644 index 0000000..4f43f74 --- /dev/null +++ b/challenges/fizzbuzz/solutions/c/function/README.md @@ -0,0 +1,3 @@ +# fizzbuzz/c/function + +Created by [@Divlo](https://github.com/Divlo) on 29 September 2021. diff --git a/challenges/fizzbuzz/solutions/c/function/solution.c b/challenges/fizzbuzz/solutions/c/function/solution.c new file mode 100644 index 0000000..75e3afd --- /dev/null +++ b/challenges/fizzbuzz/solutions/c/function/solution.c @@ -0,0 +1,22 @@ +#include +#include +#include + +int main() { + int length; + scanf("%d", &length); + for (int number = 1; number <= length; number++) { + bool is_divisible_by_3 = number % 3 == 0; + bool is_divisible_by_5 = number % 5 == 0; + if (is_divisible_by_3 && is_divisible_by_5) { + printf("FizzBuzz\n"); + } else if (is_divisible_by_3) { + printf("Fizz\n"); + } else if (is_divisible_by_5) { + printf("Buzz\n"); + } else { + printf("%d\n", number); + } + } + return EXIT_SUCCESS; +}