Member Avatar for JaBa

Hi! I make c++ programm for school and I have problem with array rotation for 90 degree. I make array rotation from one example, but there is an array rotation on wrong way, I need to make it to rotate to other way. So please help me. Here is code:

//array mas[100][100]
                     j=i; // this is cube array size like i=100;
                     for (n=0; n<=j/2; n++)
                     {
                        for (m=0; m<=j-1; m++)
                        {
                                x=n;
                                y=m;
                                tmp=mas[j-n+1][m];
                                mas[j-n+1][m]=mas[y][x];
                                tmp2=mas[j-m+1][j-n+1];
                                mas[j-m+1][j-n+1]=tmp;
                                tmp=mas[x][j-m+1];
                                mas[x][j-m+1]=tmp2;
                                mas[y][x]=tmp;
                        }
                     }

Here is input (example):
2 6
3 9

Here is output:
6 9
2 3

Needed output (I need this output):
3 2
9 6

Just do the opposite of what you are doing and it will rotate your 'cube' in the other direction.

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.