title: Calculating mean of each column in a 2D array in C?
body: <p>So let's say I have an 2D array of numbers:</p>
  
  <pre><code>int a[WEEK][DAY] = {367, 654, 545, 556, 565, 526, 437,
                      389, 689, 554, 526, 625, 537, 468,
                      429, 644, 586, 626, 652, 546, 493,
                      449, 689, 597, 679, 696, 568, 522,
                      489, 729, 627, 729, 737, 598, 552};
  </code></pre>
  
  <p>How would I calculate the mean of each column? For example, 
  (367+389+429+449+489)/5=424.6, and etc. I've figured out how to calculate the mean for each row but i'm having difficulties in doing it for each column. 
  Here is What I have so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #define WEEK 5
  #define DAY 7
  int main() {
  /* or int a[][DAY] = {367, 654, 545, 556, 565, 526, 437, */
      int a[WEEK][DAY] = {367, 654, 545, 556, 565, 526, 437,
                          389, 689, 554, 526, 625, 537, 468,
                          429, 644, 586, 626, 652, 546, 493,
                          449, 689, 597, 679, 696, 568, 522,
                          489, 729, 627, 729, 737, 598, 552};
      int i, j, weektotal, total = 0;
      double meanval;
      printf("Week Mean hit\n");
      printf("-------------\n");
      for(i = 0; i &lt; WEEK; i++) {
          weektotal = 0;
          for(j = 0; j &lt; DAY; j++) {
              weektotal += a[i][j];
              total += a[i][j];
              }
      meanval = (double)weektotal/DAY;
      printf(" %d%10.2f\n", i+1, meanval);
      }
  
  return 0;
  }
  </code></pre>
  
  <p>This current code calculates mean for each of the 5 rows.</p>