title: Reducing the number of iterations in double loop
body: <p>I have a list of circles (centre and radius), and for each circle, I need to do some processing for all circles whose centres are inside the circle.</p>
  <p>I do a simple double loop as</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  
  typedef struct Points
  {
      double x;
      double y;
      double r;
  } Points;
  
  int main()
  {
  
      int num = 10000; // number of circles
      Points c[num];   // circles
  
      for (int i = 0; i &lt; num; i++)
      {
          for (int j = 0; j &lt; num; j++)
          {
              // checking if the distance of point i and j is small than i's radius
              if (c[i].r &gt; sqrt(pow(c[i].x - c[j].x, 2) + pow(c[i].y - c[j].y, 2)))
              {
                  // do the processing
              }
          }
      }
  
      return 0;
  }
  </code></pre>
  <p>The problem is the performance. For 10,000 circles I do 100M iterations.</p>