I can't access the article. Google translate or links posted by other users don't work. HN please stop supporting paywall sites.
^^^ bool is3 = i%3 == 0 ;
bool is5 = i%5 == 0 ;
if( is3 && is5 )
{
printf("fizzbuzz\n") ;
}
else if( is3 )
{
printf("fizz\n") ;
}
else if( is5 )
{
printf("buzz\n") ;
}
else
{
printf("%d\n" , i ) ;
} #include <stdio.h>
#include <stdlib.h>
const char* table[] = { "%d\n" , "Fizz\n" , "Buzz\n" , "FizzBuzz\n" } ;
void E( int i )
{
exit( 0 ) ;
}
void F( int i )
{
size_t c = !( i%3 ) + !( i%5 )*2 ;
printf( table[c] , i ) ;
}
void ( *func[2] )( int ) = { F , E } ;
int main( void )
{
int p = 1 ;
while( 1 )
{
func[p/102]( p++ ) ;
}
return 0 ;
}
This of course only avoids conditional branches.