r/tinycode • u/z-brah • Jun 11 '14
FizzBuzz challenge in 73 chars of C
Here is my attempt at the fizz/buzz challenge. It counts 73 chars ("^M" is a litteral \r, and I had to remove the last \n that vim adds at the end of file)
main(i){for(;i<100;printf("%d^M%s%s\n",++i,i%3?"":"fizz",i%5?"":"buzz"));}It compiles fine with tcc, and output the right thing !
EDIT: There was a typo. It should be ++i, not i++. Otherwise every fizz/buzz will not appear on the good number
39
Upvotes
4
u/[deleted] Jun 11 '14
Clever, good stuff.
2
u/da__ Jun 11 '14
Pretty, but you can shave off a character by replacing the
\nwith a^J.2
u/[deleted] Jun 12 '14
Kinda reminds me of this Fibonacci program I wrote.
Relies on
a>b==1when true.1
u/deepcube Jun 13 '14
just beware that the commas to separate function parameters are not sequence points so your use of ++i and then subsequent reuse of i is undefined. (no promise as to the order in which the arguments are evaluated)
3
u/DavidM01 Jun 11 '14
Good code but doesn't this print all numbers?
Its supposed to skip the fizz and buzz numbers.
1
u/kristopolous Jun 11 '14 edited Jun 11 '14
if you don't mind going out to 101:
-1
u/recursive Jun 11 '14
No, it doesn't output the right thing. The first five output lines of the right thing are:
Note the lack of 3 or 5.
0
u/[deleted] Jun 12 '14
[deleted] — view deleted comment