1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <stdio.h> main() { int i; for(i = 1; i <= 1000000; i += 1) if(i % 15 == 0) printf("BizzBuzz\n"); else if(i % 3 == 0) printf("Bizz\n"); else if(i % 5 == 0) printf("Buzz\n"); else printf("%d\n", i); }
Refactorings
No refactoring yet !
fundamental
June 24, 2010, June 24, 2010 23:51, permalink
1 2 3 4 5 6 7 8 9 10 11
#include <stdio.h> int main() { int i; for(i=1; i<1000; ++i) if(printf("%s%s", i%3?"":"Bizz", i%5?"":"Buzz") > 0) putchar('\n'); return 0; }
fundamental
June 24, 2010, June 24, 2010 23:54, permalink
Fixing the missing non-bizz/buzz case
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <stdio.h> int main() { int i; for(i=1; i<6; ++i) { if(printf("%s%s", i%3?"":"Bizz", i%5?"":"Buzz") > 0) putchar('\n'); else printf("%d\n",i); } return 0; }
thaostra.myopenid.com
June 26, 2010, June 26, 2010 03:33, permalink
This was the result of experimenting with the re-factored code.
1 2 3 4 5 6 7 8 9 10 11 12
#include <stdio.h> int main() { int i; for(i = 1; i <= 100; ++i) if(printf("%s", i % 15 == 0 ? "BizzBuzz\n" : i % 3 == 0 ? "Bizz\n" : i % 5 == 0 ? "Buzz\n" : "" ) == 0) printf("%d\n",i); return 0; }
My knowledge of C is limited, however I know there are better implementations of this well-known program.