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