There's another problem with the above C++ code: If ny and nz
aren't constant, you can't write
double s[ny][nz];
Instead, either you allocate the array in two stages:
double** s = new (double*)[ny];
for (j=0; j < ny; ++j) s[j] = new double[nz];
Actually, the first version works -- and both C and C++ (tested here with
gcc -- not sure it it became a standard or not)) will dynamically allocate
memory for you. Try this:
int size1, size2, i, j;
cin >> size1;
cin >> size2;
double vec[size1][size2];
And enter something like "1000" and "1000" when asked for the array dimensions.
It compiles, runs, and does not segfault! :-)