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 | #include<stdio.h> int main() { int arr[10][10]; int direction = 1; int count = 1; int max = 10; int a = 0, b = -1; while (max > 0) { for (int i = 0; i < max; i++) { b = b + direction; arr[a][b] = count; count++; } max--; for (int i = 0; i < max; i++) { a = a + direction; arr[a][b] = count; count++; } direction *= -1; } for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { printf("%4d", arr[i][j]); } printf("\n"); } return 0; } | cs |
IT전공관련