Skip to content

Instantly share code, notes, and snippets.

@alexesDev
Created November 16, 2012 20:27
Show Gist options
  • Select an option

  • Save alexesDev/4090609 to your computer and use it in GitHub Desktop.

Select an option

Save alexesDev/4090609 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#define SIZE 9
int matrix[SIZE][SIZE];
int main(void)
{
int x, y, step;
int value = 81;
//int stepCount = (int)floor(SIZE / 2);
//test printed values
for(x = 0; x < SIZE; ++x)
for(y = 0; y < SIZE; ++y)
matrix[x][y] = 0;
// main part
for(y = 0; y < SIZE; ++y)
matrix[0][y] = value--;
for(x = 1; x < SIZE; ++x)
matrix[x][SIZE - 1] = value--;
for(y = SIZE - 2; y >= 0; --y)
matrix[SIZE - 1][y] = value--;
for( x < SIZE; x = 1; x < SIZE; --x)
matrix[x][SIZE] = value--;
// end main part
for(x = 0; x < SIZE; ++x, printf("\n"))
for(y = 0; y < SIZE; ++y)
printf("%2d ", matrix[x][y]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment