hello,
iam very beginer in c++ and i have home work in matrices
i want to know a method to make matrices and collect them
by using array & pointer
note i want to make a matrix code which make me type any matrices
with any number of row or column

thank you,

What do you know about new[] and delete[]? If the size has to be variable then you're going to end up messing with dynamic memory, as I assume you can't use the std::vector class. Here's some code to get you started:

int **p = new int*[M];

for ( int i = 0; i < M; i++ )
  p[i] = new int[N];

// And to release the memory:
for ( int i = 0; i < M; i++ )
  delete[] p[i];

delete[] p;

What you mean is dynamic memory allocation, check out this first and feel free to ask questions if you don't understand something :)

int **p = new int*[M];

for ( int i = 0; i < M; i++ )
  p[i] = new int[N];

// And to release the memory:
for ( int i = 0; i < M; i++ )
  delete[] p[i];

delete[] p;

Why not just int *p = new int[M]; ?
Is that because you want to have the opportunity to delete an element from the array?

>Why not just int *p = new int[M]; ?
Because then it wouldn't be a matrix? :icon_rolleyes: The usual interpretation of the term "matrix" is a rectangular array, or a two-dimensional vector. Or were you asking something completely different?

i mean how to make two matrices

and adding them and show the result as matrix too.

thanks,

>i mean how to make two matrices
If you can make one, you can make two, or three, or umpteen. :icon_rolleyes:

>are you understand me??
I are understand you just fine. :icon_rolleyes: You want me to give you code to add matrices, which isn't going to happen because you haven't given us any proof of effort yet. In fact, the only code in this thread was posted by me.

So is it that you don't understand how adding matrices works? Or are you just too lazy to turn it into code?

Comments
Excellent come back
This question has already been answered. Start a new discussion instead.