//按对角线顺序
//1 3 6
//2 5 9
//4 8 11
//7 10 12
#define M 4
#define N 3
int main()
{
int a[M][N] = { 0 };
int curVal = 1;
for (int i = 1; i < M + N; i++)
{
int nRow, nCol;
if (i <= M)
{
nRow = i - 1;
nCol = 0;
}
else
{
nRow = M-1;
nCol = i - M;
}
a[nRow][nCol] = curVal++;
while (1)
{
if (--nRow >= 0 && ++nCol <= N - 1)
a[nRow][nCol] = curVal++;
else
break;
}
}
for (int i = 0;i<M;i++)
{
for (int j = 0; j < N; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}
system("pause");
return 0;
}