1
1
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:
Divlo 2021-09-29 10:15:08 +02:00
parent e308210f16
commit a1a0c65c16
No known key found for this signature in database
GPG Key ID: 6F24DA54DA3967CF
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# fizzbuzz/c/function
Created by [@Divlo](https://github.com/Divlo) on 29 September 2021.

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