pC.NET

Welcome to oscc.kr



 숫자 달팽이 돌리기
2020-05-12 10:38:04
Hit : 1021

작성자 : 피시키드
- File #1 : 54.c(826 Byte), Download : 13

한바퀴 씩 사이클을 나누고,

그 사이클 내에서 다시 4개로 쪼개서 반복문을 돌면 된다.

홀수랑 짝수일 때 가운데가 약간 다르다는 것도 주의해야한다.

 

 

 

#include <stdio.h> // 01 02 03 04 // 12 13 14 05 // 11 16 15 06 // 10 09 08 07 int main() { int i; int j; int cnt = 0; int in; int x=1; int y=1; int n=1; int arr[50][50]; printf("input num: "); scanf("%d",&in);for (i=in-1;i>=1;i=i--) { for ( ;y<=i;y++) { cnt = cnt + 1; arr[x][y] = cnt; } for ( ; x<=i;x++) { cnt = cnt + 1; arr[x][y] = cnt; } for ( ; y>=n+1;y--) { cnt = cnt + 1; arr[x][y] = cnt; } for ( ; x>=n+1;x--) { cnt = cnt + 1; arr[x][y] = cnt; } n = n + 1; x = n; y = n; } if (cnt != in * in) { cnt = cnt + 1; arr[in/2+1][in/2+1] = cnt; } for (i=1;i<=in;i++) { for (j=1;j<=in;j++) printf("%3d", arr[i][j]); printf("\n"); } return 0;}

 

 

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

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


홀수 마방진
변수형의 제약을 넘어서 2의 n승 출력하기

Copyright (C) 1997-2025 All Rights Reserved.

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