pC.NET

Welcome to oscc.kr



 홀수 마방진
2020-05-12 10:38:55
Hit : 1181

작성자 : 피시키드
- File #1 : 53.c(689 Byte), Download : 15

마방진 풀이법(우상단으로 이동하는 것)을 C로 그대로 구현하면 된다.

 

 

#include <stdio.h> int main() { int i, j; int fx, fy; int x, y; int num; int sum; int sqr[50][50]; printf("input odd num: "); scanf("%d",&num); if (num % 2 != 1) return 1; x = 1; y = (num + 1) / 2; sqr[x][y] =1; for (i=2;i<=num*num;i++) { fx = x; fy = y; x = x - 1; y = y + 1; if (x < 1) x = num; if (y > num) y =1; if (sqr[x][y] == 0) sqr[x][y] = i; else { x = fx + 1; y = fy; sqr[x][y] = i; } } for (i=1;i<=num;i++) { for (j=1;j<=num;j++) { printf("%3d",sqr[i][j]); } printf("\n");  } return 0; }

 

* 피시키드님에 의해서 게시물 이동되었습니다 (2024-04-26 18:49)

  피시키드
회원님의 소개글이 없습니다.
 6490
 83


파스칼의 삼각형
숫자 달팽이 돌리기

Copyright (C) 1997-2025 All Rights Reserved.

Powered by
DNS server, DNS service 우분투 리눅스 웹서비스 AbuseIPDB Contributor Badge