title: Fizzbuzz program in C
body: <p>Okay, this really isn't as much a fizzbuzz question as it is a C question.</p>
  
  <p>I wrote some simple code in C for printing out fizzbuzz as is required. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      int n = 30;
      int i;
      for (i = 1; i&lt;=n; i++)
          printf("%s\n", (i % 15) == 0 ? "fizzbuzz" : (i % 5) == 0 ? "buzz" : (i % 3) == 0 ? "fizz" : i);
  }
  </code></pre>
  
  <p>Now, the last else statement obviously doesn't work since printf is accepting a string whereas 'i' is an int. 
  My question is, is there any sort of cast that I can apply to convert the 'i' into a string? </p>
  
  <p>EDIT: I should mention, what I'm really asking is if this fizzbuzz test can be done using a single print statement. No particular reason why I want it to be a single print statement only other than curiosity of as to whether it can be done.</p>
  
  <p>EDIT2: Question answered and here's my implementation:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      int i, n=30;        
      for (i = 1; i&lt;=n; i++)
          printf((!(i%3) || !(i%5)) ? "%s\n" : "%d\n", !(i % 15) ? "fizzbuzz" : !(i % 5) ? "buzz" : !(i % 3) ? "fizz" : i);
  }
  </code></pre>
  
  <p><a href="http://codepad.org/DN7yBW99" rel="nofollow">http://codepad.org/DN7yBW99</a></p>