3

Possible Duplicate:
How do you rotate a two dimensional array?

Beginner in C++ , Need to rotate to 90 degrees, I already tried to do with the help of others posts here , but without luck. Sorry for English

 # define D 9

int Ta [D][D];
short i, j;
short c=1;

for ( i=0; i < D ; i++)  {
    for ( j = 0 ;  j < D; j++)


    if ((j>i) && (j<D-i-1))  Ta[i][j]=c++; 
    else if((j>D-i-1) && (j<i)) Ta[i][j]=c++;
        else Ta[i][j]=0;  

}

for ( i = 0; i < D; i++) {
    for ( j= 0; j < D; j++) {
        printf("%3d",Ta[i][j]);
    }
    printf("\n");
}
Community
  • 1
  • 1
user1798042
  • 53
  • 1
  • 6

1 Answers1

1

the answer was : Thanks to Adam Liss

int r[D][D];

for (i=0; i<D; ++i) {
    for (j=0; j<D; ++j) {
        r[i][j] = t[D-j-1][i];
    }
}
user1798042
  • 53
  • 1
  • 6