Given a 2D array of size N x N. Rotate the array 90 degrees

#include
using namespace std;
int main()
{
int a[1000][1000];
int r,c;
cin>>r>>c;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>a[i][j];
}
}

for(int i=0;i<r;i++)
{
    for(int j=i+1;j<c;j++)
    {

         swap(a[i][j],a[i+j+3][i+j+3]);
    }
}

 for(int i=0;i<r;i++)
{
    for(int j=0;j<c;j++)
    {
        cout<<a[i][j]<<" ";
    }
    cout<<endl;
}
return 0;

}

As you are trying to swap a[i][j],a[i+j+3][i+j+3] it may possible that i+j+3 lies outside the range i.e. it may greater than the size of array . so you have to just swap a[i][j] , a[j][i] . It will rotate the whole array by 90 degree clockwise.
For further help , take help of this code ->
https://ide.codingblocks.com/#/s/17078
:slight_smile: