일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- centuryFromYear
- almostIncreasingSequence
- baekjun
- shapeArea
- Counting cells in a blob
- cpp
- 파이썬머신러닝완벽가이드
- C++
- flask
- til
- adjacentElementsProduct
- Daily Commit
- Numpy
- 10953
- markdown
- 2015 봄학기 알고리즘
- 파이썬 포렌식
- codesignal
- 수 정렬하기
- 백준
- 피보나치 수
- 2750
- codesingal
- collections.deque
- matrixElementsSum
- Sequential Search
- recursion
- Python
- data_structure
- All Longest Strings
Archives
- Today
- Total
Introfor
숫자사각형2 본문
<문제>
어떤 수 n을 입력 받아서 n 크기의 정사각형을 만드시오.
ex) n=3
1 2 3 | 1 6 7 2 5 8 3 4 9 | cs |
<소스코드>
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 | #include <stdio.h> int main() { int n = 0; int tmp = 0; int arr[100][100] = { 0 }; scanf("%d", &n); for (int i = 0; i < n; i++) { if (i % 2 == 0) { for (int j = 0; j < n; j++) { tmp++; arr[j][i] = tmp; } } else { for (int j = n - 1; j >= 0; j--) { tmp++; arr[j][i] = tmp; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%d ", arr[i][j]); } printf("\n"); } return 0; } | cs |
'Doing > C&C++' 카테고리의 다른 글
숫자마름모 (0) | 2016.11.03 |
---|---|
키와 몸무게를 입력 받아서 표준, 과체중, 저체중 출력 (0) | 2016.11.02 |
숫자사각형1 (0) | 2016.10.28 |
윤년 구하기 (0) | 2016.10.13 |
Sublime text와 Github 연동 (0) | 2016.10.13 |
Comments