1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <stdio.h> #include <stdlib.h> #define MAX 100 void pr( int n, int squ[][MAX]); void square( int n, int squ[][MAX]); int make_num(); int main( void ) { int n, squ[MAX][MAX]={0}; scanf ( "%d" , &n); square(n, squ); pr(n, squ); return 0; } int make_num(){ static int a=0; int b; b=((a++)%26)+ 'A' ; return b; } void pr( int n, int squ[][MAX]) { int i, j; for (i=0; i<2*n; i++) { for (j=0; j<2*n; j++) { if (squ[i][j]==0) printf ( " " ); else printf ( "%c " , squ[i][j]); } printf ( "\n" ); } //system("pause"); //system("cls"); } void square( int n, int squ[][MAX]) { int x=0, y=n-1, c1=1, c2=n, a=0, i; for (i=0; i<n; i++) { while (x<c2) squ[x++][y--]=make_num(); y+=2; while (x<(2*c2)-c1) squ[x++][y++]=make_num(); x-=2; while (y<(2*c2)-c1) squ[x--][y++]=make_num(); y-=2; while (y>=c2) squ[x--][y--]=make_num(); x++; c1++; } } |