Guest User

Obfuscated FizzBuzz in C

a guest
Jul 1st, 2012
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /*
  4.  * Write a program that prints the numbers from 1 to 100. But for multiples of
  5.  * three print "Fizz" instead of the number and for the multiples of five
  6.  * print "Buzz". For numbers which are multiples of both three and five print
  7.  * "FizzBuzz".
  8.  */
  9.  
  10. #define CHECK_MULT(num) (((buf = (float) index / num) == (int) buf) << (num / 5))
  11.  
  12. int main(int argc, char **argv) {
  13.     float buf;
  14.     int index;
  15.     unsigned char mult;
  16.  
  17.     for(index = 1; index <= 100; index++) {
  18.         mult = 0;
  19.         if(((mult |= CHECK_MULT(3)) & 1))
  20.             printf("Fizz");
  21.         if(((mult |= CHECK_MULT(5)) & 2))
  22.             printf("Buzz");
  23.         if(!mult)
  24.             printf("%i", index);
  25.  
  26.         puts("");
  27.     }
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment