can you please check what is the problem in this code which is throwing the error “invalid types ‘int[int]’ for array subscript”
here is the code:
hash include
using namespace std;
void rotateImage(int array[], int n){
// REVERSE THE ROWS and then TAKE TRANSPOSE:
// to reverse the rows
for (int i = 0; i < n; i++)
{
int x= 0, y=n-1;
while(x<y){
swap(array[i][x], array[i][y]);
x++;
y--;
}
}
// to transpose the matrix
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
while (i<j)
{
swap(array[i][j], array[j][i]);
}
}
}
cout<<"NEW ARRAY: "<<endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << array[i][j];
}
cout << endl;
}
}
int main()
{
int n;
cout << "Enter the value of row and column: ";
cin >> n;
int array[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << "Enter the value of array at position " << i << " , " << j << " : ";
cin >> array[i][j];
}
}
cout << "Original array: " << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << array[i][j];
}
cout << endl;
}
rotateImage(array, n);
return 0;}