Not sure if I posted correctly. I am trying to do a bubble sort on a 2D array. I want to sort the array by columns. I get it to compile but it doesn't run correctly.

include <iostream>

using namespace std;
int main()

{
int array[10][10];
int col, row;
cout<<"Enter numbers to put into row ";




        for(int i = 0; i < 9; i++){
        cin>>row;
cout<<"Enter the numbers to put into column ";
                for(int j = i+1; j < 10; j++){
                cin>>col;
                array[i][j];
}
}

int maxIndex;
for(int i=0; i<size-1;i++)

{
        maxIndex=i;
        for(int j=i+1;j<size;j++){
                if(a[j][col] > a[maxIndex][col])
                maxIndex=j;
}





 if(a[i][col] > a[maxIndex][col]) {
                                int temp = a[i][col];
                                a[i][col] = a[maxIndex][col];
                                a[maxIndex][col] = temp;
                        }
        }
}




  for(int i = 0; i < 10; i++)
                        for(int j = i+1; j < 10; j++)
                cout << array[i][j] << " ";
                                return 0;
                                }

Recommended Answers

All 4 Replies

hmm.. what is the problem with it ? can you specify it ?

i fix my for loop for cin the numbers. It should not be nested.

The problem is it compiles but doesn't run correctly.
Below is how the program runs.

Note I did fix for looops

cout<<"Enter numbers to put into row ";
        for(int i = 0; i < 9; i++){
        cin>>row;
                array[i][row];}

cout<<"Enter the numbers to put into column ";
                for(int j = 0; j < 10; j++){
                cin>>col;
                array[j][col];}

//program below

Enter numbers to put into row 2
2
2
2
2
2
2
2
2
Enter the numbers to put into column 2
3
3
34
4
3
2
2
1
3
32767 96483976 55 0 0 -2042747344 11094 -2042748928 11094 96533536 55 4195048 0 96502096 55 -2042748928 11094 0 302414976 32767 6296104 0 6295552 0 1 0 0 0 92327781 55 55 0 0 96502096 55 2 0 3 0 55 6295552 0 65535 1 55

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.