title: Summing 2D array columns in c++
body: <p>I want to sum up columns of a predefined 2 D array, but my code seems not to work. E. g. for a 2D array with rows 2 3 and 4 5
  I am getting following column sums:
  -117393687 and -113194156</p>
  
  <p>Here is the part of my code where I sum up the columns:</p>
  
  <pre><code>//sum columns
  for(i=0; i&lt;m; i++)
  {
      for(ii=0; ii&lt;m; ii++)
      {
      sum += myarray[i][ii];
      }
  cout &lt;&lt;"column sum:  "&lt;&lt;sum&lt;&lt;endl;
  {
  </code></pre>
  
  <p>Rest of my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      int i, ii, n, m, sum;
      int array[n][m];
  
      sum=0;
  
      cout &lt;"no. of rows"&lt;&lt;endl;
      cin&gt;&gt;n;
      cout &lt;"no. of columns"&lt;&lt;endl;
      cin&gt;&gt;m;
  
      for(i=0; i&lt;n; i++)
      {
          for(ii=0; ii&lt;n; ii++)
          {
              cout&lt;&lt;"row "&lt;&lt;i+1&lt;&lt;" column "&lt;&lt;ii+1&lt;&lt;endl;
              cin&gt;&gt;array[n][m];
          }
      }
  }
  
  //sum columns
  for(i=0; i&lt;m; i++)
  {
      for(ii=0; ii&lt;m; ii++)
      {
      sum += myarray[i][ii];
      }
  cout &lt;&lt;"column sum:  "&lt;&lt;sum&lt;&lt;endl;
  {
  </code></pre>