I defined this matrix with pointers, but I couldn't figure out how to print like a normal matrix print. like :

Code:

for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
cout << M[i][j] << "\t";
cout << "\n";
}

/////////////////////MY CODE/////////////////////////////

Code:

#include<iostream>
#include<math.h>
#include<time.h>
using namespace std;
#define SIZE 20
void print_matrix2(int M[][SIZE], int a);
int main() {
int M[SIZE][SIZE] = {};
int N[SIZE][SIZE] = {};
int P[SIZE][SIZE] = {};
int* ptrMatris = &M[0][0];
int* ptrMatris2 = &N[0][0];
int* ptrMatris3 = &P[0][0];
int size, a,i;
srand(time(NULL));
cout << "enter size: " << endl;
cin >> size;
a = sqrt(size);
for (i = 0;i < size;i++)
{
*(ptrMatris+i) = rand() % 11;
*(ptrMatris2 + i) = rand() % 11;
}
/*cout << "----MATRIX - 1----" << endl;
print_matrix2(M, a);
cout << endl;
cout << "----MATRIX - 2----" << endl;
print_matrix2(N, a);
cout << endl;
*/
system("pause");
}
void print_matrix2(int M[][20],int a)
{
int i, j;
for (i = 0; i < a; i++)
{
for (j = 0; j < a; j++)
cout << M[i][j] << "\t";
cout << "\n";
}
}