When you allocate an array inside a function, it is a local array, and its allocated using the stack-space. That space is limited, so when it runs out, you get an overflow. Just allocate it dynamically:
You have: double terrain1d[(divisions+1)*(divisions+1)];
Just do:
double *pTerrain1D = new double[(divisions+1)*(divisiona+1)];
Of course, use an arrow ( -> ) to access it. Other than that, its the same as what you had before.
When you're done with it, just delete it: delete pTerrain1D