How to
found a good programmer or an excellent developer and don´t die in the try,
with a simple test we can to know their skills.
“Write a
program that prints the numbers 1 at 100, but for the multiples of three prints
“Fizz” instead of the number, and for the multiples of five prints “Buzz”. For
the multiples or both, prints “FizzBuzz” ”.
Perhaps a “for”
and some “if´s and else´s” can solve the problem, but: is it sufficient? How do
you solve? I posting below my solution in language “C” and I hope yours.
main(){
int i;
for( i=1; i<=100; i++ )
printf( (i%15==0) ? "FizzBuzz ": (i%3==0) ? "Fizz " : (i%5==0) ? "Buzz " : "%d ",i );
}
int i;
for( i=1; i<=100; i++ )
printf( (i%15==0) ? "FizzBuzz ": (i%3==0) ? "Fizz " : (i%5==0) ? "Buzz " : "%d ",i );
}
No hay comentarios:
Publicar un comentario