Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- configurable fizzbuzz in C
- 2014 Damian Yerrick, Creative Commons Zero
- */
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct FBDivisor {
- unsigned int num;
- const char *symbol;
- } FBDivisor;
- const FBDivisor divs[] = {
- {3, "fizz"},
- {5, "buzz"}
- };
- int main(void) {
- for (unsigned int n = 1; n <= 100; ++n) {
- int need_num = 1;
- for (size_t p = 0; p < sizeof(divs)/sizeof(divs[0]); ++p) {
- if (n % divs[p].num == 0) {
- fputs(divs[p].symbol, stdout);
- need_num = 0;
- }
- }
- if (need_num) printf("%u", n);
- putchar('\n');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement