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; +}