#include <stdio.h> void filter(int (*cmp)(const int), int *list, int len){ int i; for(i = 0; i < len; i++){ if(cmp(list[i])) printf("%d, %s\n", i, (cmp(list[i]) == 1) ? "FIZZ BUZZ" : (cmp(list[i]) == 2) ? "FIZZ" : "BUZZ"); } } int lambda(int i){ if((i % 3 == 0) && (i % 5 == 0)) return 1; //"FIZZ BUZZ"; if(i % 3 == 0) return 2; //"FIZZ"; if(i % 5 == 0) return 3; // "BUZZ"; return 0; } int main(void) { int i; int list[100]; int (*p)(const int); for(i = 0; i <= 100; i++) list[i] = i; p = lambda; filter(p, list, 100); return 0; }
Standard input is empty
0, FIZZ BUZZ 3, FIZZ 5, BUZZ 6, FIZZ 9, FIZZ 10, BUZZ 12, FIZZ 15, FIZZ BUZZ 18, FIZZ 20, BUZZ 21, FIZZ 24, FIZZ 25, BUZZ 27, FIZZ 30, FIZZ BUZZ 33, FIZZ 35, BUZZ 36, FIZZ 39, FIZZ 40, BUZZ 42, FIZZ 45, FIZZ BUZZ 48, FIZZ 50, BUZZ 51, FIZZ 54, FIZZ 55, BUZZ 57, FIZZ 60, FIZZ BUZZ 63, FIZZ 65, BUZZ 66, FIZZ 69, FIZZ 70, BUZZ 72, FIZZ 75, FIZZ BUZZ 78, FIZZ 80, BUZZ 81, FIZZ 84, FIZZ 85, BUZZ 87, FIZZ 90, FIZZ BUZZ 93, FIZZ 95, BUZZ 96, FIZZ 99, FIZZ