title: Dividing negative number in C
body: <p><em>Hi, i am absolute newbie in programming. I am starting with learning C by book "C Programming Language (2nd Edition)" and stuck in very first example where we get exercise to write simple program that prints values of temperatures from lower to upper in 2 columns (tabs) that contains Celsius a Fahrenheit.</em></p>
  
  <p>I'v get problem because trying to edit those code for: </p>
  
  <ol>
  <li>Celsius is main system.</li>
  <li>Steps measured dynamically by dividing lower on any given number.</li>
  </ol>
  
  <p>And all work perfectly while i am using integers variables.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  main()
  {
      int celcius, farenheit;
      int lower, upper, step;
  
      lower = -273.15;
      upper = 0;
      step = lower / -10; // Dividing lower temperature by given number
  
      celcius = lower;
  
      while (celcius &lt;= upper) {
          farenheit = celcius * 9/5 + 32;
          printf("%d\t%d\n", celcius, farenheit);
          celcius = celcius + step;
      }
  }
  </code></pre>
  
  <p>But goes to absolutely random numbers when i try using float or double variables for more precise result: (There is code and output in terminal)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  main()
  {
      float celcius, farenheit;
      float lower, upper, step;
  
      lower = -273.15;
      upper = 0;
      step = lower / -10; // Dividing lower temperature by given number
  
      celcius = lower;
  
      while (celcius &lt;= upper) {
          farenheit = celcius * 9/5 + 32;
          printf("%d\t%d\n", celcius, farenheit);
          celcius = celcius + step;
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1610612736      1073741824
  1073741824      1073741824
  -1073741824     1073741824
  1073741824      536870912
  -1073741824     536870912
  1073741824      0
  -2147483648     0
  -2147483648     -2147483648
  536870912       -1610612736
  -2147483648     0
  </code></pre>
  
  <p><strong>So what happened behind that number magic and how to get this to work?</strong></p>