#include
/* fun function () function will be the first k lines two-dimensional array elements with 0
element exchange in turn1 2 3
4 5 6
7 8 9
When the value of 2 k, transform for
7 8 9
4 5 6
1 2 3
*/
Void fun (int [s] [3], int k) {
Int temp, j=2;
int i;
for(i=0; i
Temp=s [I] [2];
S [I] [2]=s [j] [2];
S [j] [2]=temp;
j--;
}
}
Int main () {
int k;
Int n=3, m=3;
The scanf (" % d ", & amp; K);
Int a, [n] [m].
for(int i=0; i
for(int i=0; i
Fun (a, k);
return 0;
}
CodePudding user response:
Your compiler didn't give you the wrong? Array you define with constant, unless you are using dynamic array, there is your fun function have to think about itCodePudding user response:
Haven't you will learn about dynamic arrayCodePudding user response:
Fun function should be to traverse the number of columns, the first k lines will in turn with the element 0, you see the columns are fixed, you wrote that how to change, the other array defining best constants, you can define his older, and then use part of it, you this is dev that a few old, mostly to vs directly killedCodePudding user response:
# include
/* fun function () function will be the first k lines two-dimensional array elements with 0
element exchange in turn1 2 3
4 5 6
7 8 9
When the value of 2 k, transform for
7 8 9
4 5 6
1 2 3
*/
Void fun (int * * s, int k) {
int temp;
int i;
For (I=0; I & lt; 3; + + I)
{
Temp=s [k] [I];
S [k] [I]=s [0] [I];
S [0] [I]=temp;
}
}
Int main ()
{
int k;
Int n=3, m=3;
The scanf (" % d ", & amp; K);
Int a=new int * * * [n].
for (int i=0; I & lt; n; + + I)
{
A [I]=new int [m].
}
for (int i=0; iFor (int j=0; j The scanf (" % d ", & amp; A [I] [j]);
Fun (a, k);
for (int i=0; I & lt; n; I++)
{
For (int j=0; J & lt; m; J++)
{
Printf (" % d \ t ", a [I] [j]);
}
printf("\n");
}
for (int i=0; I & lt; n; + + I)
{
The delete [] a [I];
}
The delete [] a;
return 0;
}
VS2015 debugging results
Please refer to the "dynamic allocation multidimensional arrays in c + +"
"To the use of two dimensional array 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.htmlI hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html