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 [2]
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 [2], but A [2] = {2,4}
Then i = 3 will not be executed (the array is already full)
and further
i & lt; = 2 j & lt; = 3 a [2] = {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;
}
Answer 1, Authority 100%
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 [1] a [1] a [1] ... (M time)
A [2] A [2] A [2] ... (M times)
A [3] A [3] A [3] ... (M times)
....
A [N] A [N] A [N] ... (M times)
(Let’s remind once again – in your array no a [n]
element).