Skip to content

Instantly share code, notes, and snippets.

@jwon0615
Created March 22, 2018 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwon0615/3f1599a12a3771dba3af7696ab532874 to your computer and use it in GitHub Desktop.
Save jwon0615/3f1599a12a3771dba3af7696ab532874 to your computer and use it in GitHub Desktop.
1510 : 홀수 마방진
#include<stdio.h>
int main()
{
int n, i, j, d[50][50], m = 1, a, b;
scanf("%d", &n);
for(i = a = 0, b = n / 2; i < n; i++)
{
for(j = 0; j < n; j++)
{
d[a][b] = m++;
if(j == n - 1) break;
a = (a - 1 + n) % n;
b = (b + 1) % n;
}
a = (a + 1) % n;
}
for(i = 0; i < n; i++, puts(""))
for(j = 0; j < n; j++)
printf("%d ", d[i][j]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment