Home c++ tell me whether I think C++ matrix

# tell me whether I think C++ matrix

Author

Date

Category

initially had a code that turned out the matrix.

I made 2 columns of 3 numbers in the range from 1 to 6.

then began to experiment to see what will be

initially was `int a [n] [m]; CIN & GT; & GT; a [i] [j]; COUT & LT; & LT; A [i] [J]; `

I removed `[M], [j] `

and ultimately the values ​​are

``````2 2 2
4 4 4.
``````

I think the following

``````a [n] = a 
i & lt; = 3 j & lt; = 2
i = 1.
j = 1 I write the number 1 A [i] = {1, place for the second number}
J = 2 I write the number 2 A [I] = {2, the place for the second number} (number 1 overwritten in number 2)
i = 2.
J = 1 I write a number 3 A [I] = {2,3}
J = 2 I write the number 4 A [i] = {2,4} (number 3 overwritten in number 4)
Since A [I] = A , but A  = {2,4}
Then i = 3 will not be executed (the array is already full)
``````

and further

``````i & lt; = 2 j & lt; = 3 a  = {2,4}
i = 1 (took the first element of the array)
J = 1 2
J = 2 2
J = 3 2
i = 2 (took 2 element of the array)
J = 1 4
J = 2 4
J = 3 4
``````

True or I just got a picture of the picture that everything would be converged?

Code:

``````# include & lt; iostream & gt;
Using Namespace STD;
INT MAIN ()
{
SETLOCALE (LC_ALL, "RUS");
int i, j, n, m;
COUT & LT; & LT; "Enter the number of lines of the matrix" & lt; & lt; Endl;
CIN & GT; & GT; N;
COUT & LT; & LT; "Enter the number of columns of the matrix" & lt; & lt; Endl;
CIN & GT; & GT; M;
int a [n];
COUT & LT; & LT; "Enter the matrices" & lt; & lt; Endl;
for (i = 1; i & lt; = m; i ++) {
For (j = 1; j & lt; = n; j ++) {
CIN & GT; & GT; A [I];
}
}
COUT & LT; & LT; "Your Matrix \ N";
For (i = 1; i & lt; = n; i ++) {
for (j = 1; j & lt; = m; j ++) {
COUT & LT; & LT; a [i] & lt; & lt; "\ t";
}
COUT & LT; & LT; Endl;
}
Return 0;
}
``````

Even if you are compiled by gnuxe 🙂 `int A [N]; `, you still do nonsense – just rewrite the same elements of the array …

We will lower what `m `and `n `may be different and you can jump out beyond the boundaries of the array. And even the fact that the elements of the array are numbered from 0.

That’s just if all this is omitted and not to pay attention – then yes, here is here

``````for (i = 1; i & lt; = m; i ++) {
For (j = 1; j & lt; = n; j ++) {
CIN & GT; & GT; A [I];
}
}
``````

You just `n `once rewrite `a [i] `element, pushing what was introduced earlier.

And here

``````for (i = 1; i & lt; = n; i ++) {
for (j = 1; j & lt; = m; j ++) {
COUT & LT; & LT; a [i] & lt; & lt; "\ t";
}
COUT & LT; & LT; Endl;
}
``````

you output

``````a  a  a  ... (M time)
A  A  A  ... (M times)
A  A  A  ... (M times)
....
A [N] A [N] A [N] ... (M times)
``````

(Let’s remind once again – in your array no `a [n] `element).

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.