Last active
December 19, 2015 19:19
-
-
Save Experiment5X/6005216 to your computer and use it in GitHub Desktop.
Sick code that rotates a 2D array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void printThing(char array[3][3]) | |
{ | |
for (int y = 0; y < 3; y++) | |
{ | |
for (int x = 0; x < 3; x++) | |
{ | |
printf("%c", array[y][x]); | |
} | |
printf("\n"); | |
} | |
} | |
int main() | |
{ | |
char oldImage[3][3] = { { '1', '2', '3' }, {'4', '5', '6' }, {'7', '8', '9' } }; | |
char newImage[3][3]; | |
printThing(oldImage); | |
for (int y = 0; y < 3; y++) | |
{ | |
for (int x = 0; x < 3; x++) | |
{ | |
newImage[x][y] = oldImage[y][x]; | |
} | |
} | |
printf("\n\n"); | |
printThing(newImage); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment