title: Project Euler #11 producing different results every time it is run?
body: <p>I am fairly new to c++ and programming in general, so I was doing questions on project euler to practice. I ran into this problem on problem 11:</p>
  
  <p>I started with a 2 dimensional 20 by 20 array of all the numbers that I needed to input, then difined several functions; one to cycle through and find the largest forward diagonal product, one for the largest backwards direction ect... so once all of these had been run, the returns from each one were compared to find the largest. </p>
  
  <p>As far as I can tell they all work appart from the vertical one, which seems to produce different results every time and be out by about a factor of 100.</p>
  
  <p>the horrizontal one looks like this and seems to work:</p>
  
  <pre><code>int horizontal(int v[20][20]){
      int x = 0, y = 0 ,out = 1, attempt = 1;
      for (x = 0; x &lt;= 15; x++){
          for (y = 0; y &lt;= 20; y++){
              attempt = v[x][y]*v[x+1][y]*v[x+2][y]*v[x+3][y];
              if (attempt &gt;= out)
                  out = attempt;
  </code></pre>
  
  <p>The vertical one which produces varying results:</p>
  
  <pre><code>int vert(int v[20][20]){
      int x = 0, y = 0 ,out = 1, attempt = 1;
      for (y = 0; y &lt;= 15; y++){
          for (x = 0; x &lt;= 19; x++){
              attempt = v[x][y]*v[x+1][y]*v[x+2][y]*v[x+3][y];
              if (attempt &gt;= out)
                  out = attempt;
          }
      }
      return out;
  }
  </code></pre>
  
  <p>I can't understand why the output would change each time for the vertical one and not the others.</p>