title: C language calculation in printf
body: <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
  int x;
  x = (10+20)*(1.0/2);
  printf("%d", x);
  return 0;
  }
  </code></pre>
  
  <p>the output is</p>
  
  <pre><code>15
  </code></pre>
  
  <p>and in another form:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
  printf("%d", (10+20)*(1.0/2));
  }
  </code></pre>
  
  <p>the output is </p>
  
  <pre><code>0
  </code></pre>
  
  <p><code>1.0/2</code> is <code>0.5</code> when calculate in integer variable <code>x</code>,
  but <code>1.0/2</code> is <code>0</code> when calculate in <code>printf</code> with <code>%d</code> (I think...)</p>
  
  <p>I cannot understand this situation...</p>
  
  <p>In addition, when I change <code>%d</code> to <code>%f</code> in the second code, the output is <code>15.000000</code></p>
  
  <p>I'm using DEV C++ in Windows 8.</p>