# hwo to change and remove the value of array(2 dimention

+1 vote
asked Nov 24, 2019

#include <stdio.h>
int fb(int m,int a[][2]);
int main() {
int m=4;
int a[4][2]={{3,19},{11,33},{18,80},{80,100}};
fb(m,a);
return 0;
}
int fb(int m,int a[][2]) {
int i,j,tem;
for(i=0;i<m;i++){
a[i][0]--;
}
for(j=m*2-1;j>0;j--){
for(i=0;i<j;i++){
if (a[i]>a[i+1]){
tem=*a[i+1];
*a[i+1]=*a[i];
*a[i]=tem;
}
}
}
for(i=0;i<m*2;i++)
printf("%d\n",*a[i]);

}

outpute:

2
10
17
79
-766854112
0
0
67902437

output i want:

2, 10, 17, 19, 33, 79, 80, 100

## 3 Answers

+1 vote
answered Nov 25, 2019 by (2,950 points)
selected Jan 4, 2020 by 王浩

Best answer
1. You can't swap rows of the 2D array with pointers. That's not how it works.

2. You can't compare entire rows of a 2D array (which is basically comparing two 1D arrays...).

3. Using "m*2-1" doesn't mean your 2D array magically gets bigger. Your array is exactly [2][4] and trying to print out a number (or actually a row in this case?) at a position "a[7]" (which is result of "4*2 - 1") doesn't help.

4. If you're trying to sort a 2D array then in my opinion flattening it to 1D, sorting it and then putting it back into 2D is your best bet. https://onlinegdb.com/HJWptKOnB - here's an example. Quick sort (which is the name of 1 of the most popular sorting methods) implementation is not mine as I was too lazy to write it myself.
0 votes
answered Nov 24, 2019 by (570 points)
can you please elaborate your code ,

i cant just understand the working or objective of this code

first , what you want to to.  (aim of the code)

second , give your input values.

third , what are the expected outputs ?
0 votes
answered Nov 25, 2019 by (1,250 points)