title: Printing a matrix
body: <p>The problem is: Given the height (h) and width (w) of a canvas (in other words, a 2D array) on the first line; and the co-ordinates of the centre (x, y) and the radius (r) of a circle, print the canvas. If an element of the 2D array is within the circle, print <code>#</code> else print <code>.</code>. Below is what I have tried, but for the life of me I can't figure out why the 2D matrix only contains <code>.</code>s. Please throw some light:</p>
  
  <pre><code>#include &lt;math.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;limits.h&gt;
  #include &lt;stdbool.h&gt;
  
  typedef struct point {
      int x;
      int y;
  } point;
  
  float distance(point p, point q) {
      return sqrt((p.x - q.x)*(p.x - q.x) + (p.y - q.y)*(p.y - q.y));
  }
  
  int withinCircle(point circleCentre, point p, int radius) {
      float dist = distance(circleCentre, p);
      if (!(dist &gt; (float) radius)) {
          return 1;
      } else {
          return 0;
      }
  }
  
  int main(void){
      point pixel;
      int w, h;
      scanf("%d %d",&amp;w,&amp;h);
      char *canvas = malloc(w * h);
  
      int circleX, circleY; 
      int r; 
      scanf("%d %d %d",&amp;circleX,&amp;circleY,&amp;r);
      point circleCentre;
      circleCentre.x = circleX; circleCentre.y = circleY;
  
      for (int i = 0; i &lt; h; i++) {
          for (int j = 0; j &lt; w; j++) {
              pixel.x = j; pixel.y = i;
              if (withinCircle(circleCentre, pixel, r)) {
                  *(canvas + i + j) = '#';
              } else {
                  *(canvas + i + j) = '.';
              }
          }
      }
  
      for (int i = 0; i &lt; h; i++) {
          for (int j = 0; j &lt; w; j++) {
                printf("%c", *(canvas + i + j));
          }
          printf("\n");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Output (20 and 16 are the width (w) and height (h) respectively. 9, 6 and 5 are the circle's X co-ordinate (x), Y co-ordinate (y) and radius (r) respectively):</p>
  
  <pre><code>20 16
  9 6 5
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  ....................
  </code></pre>