Skip to content

Instantly share code, notes, and snippets.

@Experiment5X
Last active December 19, 2015 19:19
Show Gist options
  • Save Experiment5X/6005216 to your computer and use it in GitHub Desktop.
Save Experiment5X/6005216 to your computer and use it in GitHub Desktop.
Sick code that rotates a 2D array.
#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