First may I suggest some changes in your style of coding to make the code more easy to read.
1) Not so much indentation. You are indenting way to far in and it makes it hard to read. I would suggest anywhere from 2 spaces through 6 spaces for each indentation level.
2) Declare variables right before you are about to use them. When you declare all the variables for the given scope at the top users will keep having to scroll up to find out what each on is and what value they have. Also declare your loop indexes inside the for loops it makes it much cleaner. So instead of this
int n,j,i,hold;
I would suggest something like this.
1 2 3 4
|
int n;
cout << "Enter column number (0 to " << col-1 << "):";
cin >> n;
cout << "Before : " <<endl;
|
hold inside the if statement
1 2 3 4 5 6 7 8
|
if ( j==n)
{
int hold = a[0][j];
a[0][j] = a[0][j+1];
a[0][j+1] = hold;
cout << a[i][j] << " " << endl;
}
|
for (int i=0; i<row ; i++)
for (int j=0 ; j<col ; j++)
The only reason you would want the index variables outside of the for loop would be if you needed to use the index outside of the loops scope for some reason, which you don't do here.
Them are just a few tips for you regarding formatting.\
For your current loop you don't need the row loop since you are not indexing the row only the column.
As for your problem... What exactly is it doing? Other then saying that it doesn't work we could use some more information on the error. Because I don't really see anything wrong with it, though I only did a quick search through it.