3 ms·
I've always liked this c++ implementation of FizzBuzz, its not the most clear or logical but its short; const char* outs[] = { "%d\n", "Fizz\n", "Buzz\n",
by Robadob 12y ago
I've always liked this c++ implementation of FizzBuzz, its not the most clear or logical but its short;
const char* outs[] = { "%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n" };
for (int i = 1; i < 101; i++)
printf(outs[((((i%5)==0)<<1)+((i%3)==0))], i);
- heinrich5991 12y agoIs that allowed by the standard? (Passing a parameter to `printf` but not referencing it, in the non-"%d\n" case?)
- kps 12y agoC11 §7.21.6.1 If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored. but that's just a consequence of stdarg, which does not require all supplied arguments to be consumed.