title: Reduce the fraction to lowest terms
body: <p>Im reading the book C Programming A Modern Approach. I have a exercise where I should reduce fraction to the lowest form.</p>
  
  <p>The Hint that the author gives me, Is that I first can compute the GCD of the numerator and denominator, and then divide the numerator and denominator by the GCD.</p>
  
  <p>Here is my program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  
  int main(void)
  {
      int frac1;
      int frac2;
      int gcd;
  
      int a;
      int b;
      int c;
  
      printf("Enter a fraction: ");
      scanf("%d/%d", &amp;frac1, &amp;frac2);
      b = frac1;
      a = frac2;
  
      //Calculate GCD
      c = a % b;
  
      while(gcd &gt; 0)
      {
          a = b;
          b = c;
          c = a % b;
  
          if(c &lt;= 0)
          {
              gcd = b;
              break;
          }
      }
  
  
      //Divide the numerator and denominator with the GCD
      frac1 /= gcd;
      frac2 /= gcd;
  
      printf("In lowest terms %d/%d\n", frac1, frac2);
      return 0;   
  }
  </code></pre>
  
  <p>When I give 6/12 as input, I get the following error message: Floating point exception</p>
  
  <p>How can I compute the GCD of the numerator and denominator separately?</p>