title: Calculating PI using Monte Carlo method gives imprecise answer
body: <p>I am trying to calculate PI using Monte Carlo method. My code gives the result 3.000 no matter how big MAXLEN is. After debugging it many times, I couldn't get what I'm doing wrong. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define sqr2(x) ((x)*(x))
  #define frand() ((double) rand() / (RAND_MAX))
  #define MAXLEN 1000
  
  
  int circumscribed(int radius){
      float xcoord = frand();
      float ycoord = frand(); 
      float coord = sqr2(xcoord) + sqr2(ycoord);
  
      if(coord &lt;= radius)
          return 1;
      return -1;      
  }
  
  int main()
  {
      int i;
      int circles = 0, rect = 0;;
      for(i = 0; i &lt; MAXLEN; i++)
      {
          if(circumscribed(1) &gt; 0)   // if(circumscribed(1)) shoul be enough but it doesn't work. Very odd in my opinion.
              circles++;
          rect++;  //this is equal to MAXLEN, I just used it for debugging
      }
  
      float PI = 4 * circles / rect;
      printf("PI is %2.4f: \n", PI);
      return 0;   
  }
  </code></pre>