Hi there,
When I try the fizz buzz exercise, I think up with an interesting solution that I didn’t know why it works.
The codes are compact but it really works.
#include <stdio.h>
void main(void){
for(int i = 1; i <= 100; i++){
(i%3==0)&&(i%5==0)?printf(“FizzBuzz\n”):
i%3==0?printf(“Fizz\n”):
i%5==0?printf(“Buzz\n”):
printf("%d\n", i);
}
}//end main
It seems that tenary operation can be nested. Is that right?
3 posts - 2 participants