Advertisement
MAKN

fizzbuzz.c

Oct 29th, 2023
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //Word count
  5. #define WORD_C 3
  6.  
  7. //Word definitions
  8. #define WORD_S {"Fizz","Buzz","Bizz"}
  9.  
  10. //Words will be added only to odd numbers in sequence
  11. #define WORD_F i*2+3
  12.  
  13. int main() {
  14.     char words[WORD_C][20] = WORD_S;
  15.     int wordc[WORD_C];
  16.     size_t str_size = 0;
  17.     for (int i=0;i < WORD_C;i++) {
  18.         int f = WORD_F;
  19.         wordc[i] = f;
  20.         str_size += strlen(words[i]);
  21.     }
  22.     ++str_size;
  23.  
  24.     char str[str_size];
  25.  
  26.     for (int i=1;i < 100;i++) {
  27.         strcpy(str,"\0");
  28.         for (int j=0;j < WORD_C;j++) {
  29.             if (i%wordc[j] == 0) {
  30.                 strcat(str,words[j]);
  31.             }
  32.         }
  33.         if (strcmp(str,"\0") == 0) {
  34.             printf("%d\n",i);
  35.             continue;
  36.         }
  37.         puts(str);
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement