谁能帮我看看我的哪里错了 谢谢
题目是:录入10对数字 是数组[10][2], 要求把第一列数字是从大到小排列,如果第一列数字相同的话,第二列数字从小到大排列. 输出后就像这样:2 3 65 12 23 3 6 98 25 10 65 3 1 2 2 1 43 12 63 23
Sorted in descending order for first element and ascending for second element of pair:
65 3
65 12
63 23
43 12
25 10
23 3
6 98
2 1
2 3
1 2
我写的是:
#include <stdio.h>
#define ROWS 10
#define COLS 2
int main (int argc, char *argv[]) {
int A[ROWS][COLS],i,j,count_1,count_2,min,max_2;
printf("Enter 10 pairs of integers:\n\n");
for (i=0;i<ROWS;i++){
for (j=0;j<COLS;j++){
scanf("%d",&A[i][j]);
}
}
for (i=0;i<ROWS;i++){
for(count_1=i+1;count_1<ROWS;count_1++){
if (A[i][0]<A[count_1][0]){
min=A[i][0],A[i][0]=A[count_1][0],A[count_1][0]=min;
if (A[i][0]==A[count_1][0]){
for(j=0;j<COLS;j++){
for(count_2=j+1;count_2<COLS;count_2++){
if(A[i][j]>A[i][count_2]){
max_2=A[i][j],A[i][j]=A[i][count_2],A[i][count_2]=max_2;
}
}
}
}
}
}
}
printf("Sorted in descending order for first element and ascending for second element of pair:\n");
for(i=0;i<ROWS;i++){
printf("%d%5d\n",A[i][0],A[i][1]);
}
printf("\n");
return 0;
}
我写的非常难看 各位见谅了
哪位高手能帮我稍微详细的告诉我哪里错了 非常感谢