about matrix

Dear all, if I define a matrix like double arrayP[N][M];.

should I access it like

1
2
3
4
5
6
7
for ( i = 0; i<= N-1; i++)
		{
			for(j = 0; j<= M-1; j++)
			{	
				arrayP[i][j]=randgauss(-1,1,0.1,0);
			}
		}


or

1
2
3
4
5
6
7
for ( i = 1; i<= N; i++)
		{
			for(j = 1; j<= M; j++)
			{	
				arrayP[i][j]=randgauss(-1,1,0.1,0);
			}
		}
Neither the first variant nor the second. Use the following for statements

1
2
3
4
5
6
7
for ( int i = 0; i < N; i++ )
{
	for ( int j = 0; j < M; j++ )
	{	
		arrayP[i][j] = randgauss(-1,1,0.1,0);
	}
}
The first one is correct. vlad shows a better way to write it.
Thanks for your help!
Topic archived. No new replies allowed.