Advertisement
Guest User

Fizzbuzz w/o if

a guest
Nov 30th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5.   void **actions = (void **)malloc(4);
  6.   actions[0] = &&number;
  7.   actions[1] = &&fizz;
  8.   actions[2] = &&buzz;
  9.   actions[3] = &&fizzbuzz;
  10.   int a = 0;
  11.   int b, c;
  12. loop:
  13.   a++;
  14.   b = !(a % 3);
  15.   c = !(a % 5) << 1;
  16.   goto *actions[b | c];
  17. number:
  18.   printf("%d\n", a);
  19.   goto loop;
  20. fizz:
  21.   printf("fizz\n");
  22.   goto loop;
  23. buzz:
  24.   printf("buzz\n");
  25.   goto loop;
  26. fizzbuzz:
  27.   printf("fizzbuzz\n");
  28.   goto loop;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement