#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
#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
#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.
#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.