My fizzbuzz in C

11 04 2013

This is my version of the fizzbuzz test, written in C:

char *arr[] = {"%d\n", "fizz\n", "buzz\n", "fizzbuzz\n"}; 
for (int i=1; i<=100; i++) printf(arr[!(i%3)+2*!(i%5)], i);

or rephrased in a more readable format:

char *arr[] = {"%d\n", "fizz\n", "buzz\n", "fizzbuzz\n"}; 

int i, index;

for (i=1; i<=100; i++)
{
	index = !(i%3) + 2 * !(i%5);
	printf( arr[index], i);
}
Advertisements