fork download
  1. #include <stdio.h>
  2.  
  3. void filter(int (*cmp)(const int), int *list, int len){
  4. int i;
  5. for(i = 0; i < len; i++){
  6. if(cmp(list[i])) printf("%d, %s\n", i, (cmp(list[i]) == 1) ? "FIZZ BUZZ" : (cmp(list[i]) == 2) ? "FIZZ" : "BUZZ");
  7. }
  8. }
  9.  
  10. int lambda(int i){
  11. if((i % 3 == 0) && (i % 5 == 0)) return 1; //"FIZZ BUZZ";
  12. if(i % 3 == 0) return 2; //"FIZZ";
  13. if(i % 5 == 0) return 3; // "BUZZ";
  14. return 0;
  15. }
  16.  
  17. int main(void) {
  18. int i;
  19. int list[100];
  20. int (*p)(const int);
  21.  
  22. for(i = 0; i <= 100; i++)
  23. list[i] = i;
  24. p = lambda;
  25. filter(p, list, 100);
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
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