How do I create a n*n matrix with a Do loop? [closed]

I'm trying to create an n*n matrix that would follow this criteria

1    2    3   ...  n
n+1  n+2  n+3 ...  2n
2n+1 2n+2 2n+3 ... 3n
.                  .
.                  .
.                  .
(n-1)n+1 ........ n^2


How would I be able to create this matrix using a table or a do loop? This is what I've created so far, but it doesn't follow the criteria unfortunately.

n = Input["What positive integer would you like to start your matrix with?"];
x = ConstantArray[0, {n, n}];
Do[x[[i, j]] = i + j, {i, 1, n}, {j, 1, n}]
x // MatrixForm

• Why not use Partition[Range[n^2], n]? Commented Feb 16, 2017 at 17:17
• you didn't like the answers over here: stackoverflow.com/q/42240155/1004168 ? Commented Feb 16, 2017 at 20:06
• This is a version of (111631) Commented Feb 18, 2017 at 2:55

Better to use Table:

n = Input["What positive integer would you like to start your matrix with?"];

Table[i + j*n, {j, 0, n - 1}, {i, n}]


I suggest you define a function, m to create your matrix. Here are two possible for m

Carl Woll

m[n_] := Partition[Range[n^2], n]


m_goldberg

m[n_] := ArrayReshape[Range[n^2], {n, n}]


In either case

m[3]//MatrixForm