Home c++ Dynamic Upper-Engine Matrix

Dynamic Upper-Engine Matrix

Author

Date

Category

You need to set the upper triangular size of size 3×3. The size of the strings is set dynamically.

int * matrix [3] = {new int [3], new int [2], new int};

In this case, it will turn out something as follows:

 Enter here a description of the image

And you need:

 Enter here a description of the image

How to do so? I tried to create all the lines of 3 size 3 and then delete the first unnecessary elements by the Delete operator, but the compiler swears.


Answer 1

What you wrote is an absolutely correct way to specify the upper triangular matrix, at the same time, the question is only as you will interpret it for yourself, as well as how to bypass. In memory, it looks like this: there are 3 positions of an element of 4 or 8 bytes (depending on the discharge of the application), and each of them refers to 3 different pieces of RAM.

Delete items separately from the dynamic array can not, only the entire entire array.

Here you are an example of how I interpreting this matrix as a vertical degree.

int * matrix [3] = {new int [3], new int [2], new int};
 for (int i = 0; i & lt; 3; ++ i)
 {
  For (int j = i; j & lt; 3; ++ j)
  {
   Matrix [i] [j - i] = 1;
  }
 }
 for (int i = 0; i & lt; 3; ++ i)
 {
  for (int k = 0; k & lt; i; ++ k) cout & lt; & lt; "\ t";
  For (int j = 0; j & lt; 3 - i; ++ j)
   COUT & LT; & LT; Matrix [i] [j] & lt; & lt; "\ t";
  COUT & LT; & LT; Endl;
 }

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions