#include #include #include int one, two, three, five, ten, onehundred; int digit_base; char * fizz; char * buzz; char * fizzbuzz; char ** strings; void prepare_strings(void); void show(int); void free_stuff(void); int main (void) { if (one) one /= one; else one ++; two = one + one, three = one + two, five = two + three; // yay maths ten = five * two, onehundred = ten * ten; digit_base = ten * five - two; prepare_strings(); int x; for (x = one; x <= onehundred; x ++) show(x); free_stuff(); return one - one; // can't do return 0! } void show (int number) { int matched; if (matched) matched = !matched; if (!(number % three)) matched ++; if (!(number % five)) matched += two; if (matched) puts(strings[matched]); else { if (number >= ten) putchar(digit_base + number / ten); putchar(digit_base + number % ten); putchar(ten); // newline } } void free_stuff (void) { free(fizz); free(buzz); free(fizzbuzz); free(strings); } void prepare_strings (void) { fizz = calloc(five, one); buzz = calloc(five, one); fizzbuzz = calloc(five, two); char letter_base = onehundred - five + one; char b = letter_base + two, f = letter_base + five + one, i = letter_base + ten - one, u = letter_base + ten * two + one, z = letter_base + five * five + one; *fizz = f, fizz[one] = i, fizz[two] = fizz[three] = z; *buzz = b, buzz[one] = u, buzz[two] = buzz[three] = z; strcpy(fizzbuzz, fizz); strcat(fizzbuzz, buzz); strings = malloc(onehundred); // let's say that sizeof(char *) is a constant, so I won't use it strings[one] = fizz, strings[two] = buzz, strings[three] = fizzbuzz; }