0% found this document useful (0 votes)
2 views1 page

Rotate Matrix in C Programming

The document contains C code that reads in a 2D array, transposes it by writing the values to a 1D array in column-major order, then prints out the transposed array.

Uploaded by

dvb7jd7vsm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Rotate Matrix in C Programming

The document contains C code that reads in a 2D array, transposes it by writing the values to a 1D array in column-major order, then prints out the transposed array.

Uploaded by

dvb7jd7vsm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <stdio.

h>

int main(void) {
int length;
int num[100][100];
int new[10000];
int n;
while ((scanf("%d\n",&length)!=EOF)){
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
scanf("%d ", &num[i][j]);
};
};

for(int i=0; i<length; i++){


for(int j=length-1 ;j>=0; j--){
new[n]=num[j][i];
n++;
};
};

for(int i=0; i<length*length; i++){


printf("%d",new[i]);
if((n+1)%length==0){
printf("\n");
};
};
};
return 0;
}

You might also like