Study
2008. 9. 18. 21:38
Magic Square 작성 C 소스
#include <stdio.h> #define MAX_SIZE 15 void main() { int square[MAX_SIZE][MAX_SIZE]; int i,j,row,column; int count; int size; printf("Enter the size of the square :"); scanf("%d",&size); if (size < 1 || size > MAX_SIZE + 1) { fprintf(stderr,"Error! Size is out of range\n"); //exit(1); } if (!(size%2)) { fprintf(stderr, "Error! Size is even\n"); //exit(1); } for (i=0;i<size;i++) for(j=0;j<size;j++) square[i][j]=0; square [0][(size-1)/2]=1; i=0; j=(size-1)/2; for (count=2;count<=size*size;count++) { row=(i-1<0)?(size-1):(i-1); column=(j-1<0)?(size-1):(j-1); if (square [row][column]) i=(++i)%size; else{ i=row; j=(j-1<0)?(size-1):--j; } square[i][j]=count; } printf("Magic Square of size %d: \n\n",size); for (i=0;i<size;i++) { for(j=0;j<size;j++) printf("%5d",square[i][j]); printf("\n\n"); } printf("\n"); }
공유하기
게시글 관리
솔직한 목소리
blog
profile
tag cloud
travel log
guest book
by
bslime
전체보기
(52)
목소리
(1)
영화
(0)
음악
(0)
Study
(34)
Security
(12)
Web
(2)
WLAN
(7)
Network
(1)
System
(1)
Wargame
(5)
Web
(0)
Reverse Engineering
(3)
Crypto
(2)
초대장
잘했어요
티스토리
Algorithm
미로
Maze
padocon
폐인
CTF
삽질
«
2025/05
»
일
월
화
수
목
금
토
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
darktoil.
인생여전龍군.
슝이.
MR-J@.
미움.
vvipbeom.
Copyright ⓒ 2010.
bslime
, Skin designed by
Creasmworks.
All rights reserved.
티스토리툴바