Home > Back-end >  Two-dimensional array as a parameter, the calling function
Two-dimensional array as a parameter, the calling function

Time:06-04

Transposed matrix, can't call a function, z (x) can not call, teach,
# include
Int main ()
{
Int I, j, m, n;
Int x [100] [100].
Void z (int x [] [100]).
The scanf (" % d % d ", & amp; M, & amp; n);
for(i=0; ifor(j=0; JThe scanf (" % d ", & amp; [I] x [j]);
Z (x);
for(i=0; i{
for(j=0; JPrintf (" % 5 d, "x [I] [j]);
printf("\n");
}
}

Void z (int x [] [100])
{
Int temp=0, I, j;
for(i=0; i<100; I++)
for(j=0; J<100; J++)
{
Temp=x [I] [j];
[I] [j]=x x [j] [I];
X [j] [I]=temp;
}
}

CodePudding user response:

Can try int * * x

CodePudding user response:

Please baidu dynamic array related knowledge,
For example the following code
 
Int m=2;
Int n=3;
Int * * mArray=new int * [m].
for (int i=0; IMArray [I]=new int [m] ();
}

CodePudding user response:

refer to the second floor jean7155 response:
please baidu dynamic array related knowledge,
For example the following code
 
Int m=2;
Int n=3;
Int * * mArray=new int * [m].
for (int i=0; IMArray [I]=new int [m] ();
}

Thank you haven't learned this, continue to learn,

CodePudding user response:

Void z (int [100] [100]).
This sentence to put int main () in front of,

Z function inside the body, you think about it, since it is exchange data, j is from 0 to 100 cycle?
You now this cycle as a result, such as x [1] [2] and [2] x [1] will be exchanged twice? !!!!!
For the first time I=1, j=2; Exchange; The second time I=2, j=1, it is not exchange it again,
This exchange of two times, whether is Bai Waner

So the double loop inside the z is can't do that,

CodePudding user response:

Wow yes, thank you

CodePudding user response:

Recommend and dynamic array an array of blog

https://blog.csdn.net/jean7155/article/details/103339492
I write learning summary notes today, welcome to communicate ah

CodePudding user response:

Please refer to the "two dimensional array and pointer in c + +"
"C + + 2 d array
"Wish I could help you!

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related