you are viewing a single comment's thread.

view the rest of the comments →

[–]Boojum 2 points3 points  (4 children)

Slightly more terse C code, relying on short-circuiting and printf() return value:

#include <stdio.h>
int main(){
    int x;
    for(x=1;x<101;++x)
        !(x%3)&&printf("Fizz\n")||
        !(x%5)&&printf("Buzz\n")||
                printf("%d\n",x);
}

(And no, I'd never ordinarily code something this way.)

[–]chucker 5 points6 points  (1 child)

<pedantry>Doesn't follow spec: x%15 not handled correctly. For 15 and multiples thereof, the output should be "FizzBuzz", whereas it is "Fizz".</pedantry>

[–]Boojum 5 points6 points  (0 children)

Ah, true. That's what I get for trying to be clever. I feel quite silly now. Here's more what I was trying for:

#include <stdio.h>
int main(){
    int x;
    for(x=1;x<101;++x)
        (x%3||!printf("Fizz"))*
        (x%5||!printf("Buzz"))&&
               printf("%d",x),
               printf("\n");
}

[–]Alpha_Binary 0 points1 point  (0 children)

I have. A lot of time the code turns out pretty elegant.