다차원배열1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <stdio.h> int main(void) { int a[50][50]; int i, j; int key; scanf("%d", &key); for (i = 0; i < key; i++) { for (j = 0; j < key; j++) { a[i][j] = j+i*key+1; } } for (i = 0; i < key; i++) { for (j = 0; j < key; j++) { printf("%d ", a[i][j]); } puts(""); } } | 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 | #include <stdio.h> int main(void) { int a[50][50]; int i, j; int key; scanf("%d", &key); for (i = 0; i < key; i++) { for (j = 0; j < key; j++) { a[i][j] = i+j*key+1; } } for (i = 0; i < key; i++) { for (j = 0; j < key; j++) { printf("%d ", a[i][j]); } puts(""); } } | cs |
다차원배열3
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 35 | #include <stdio.h> int main(void) { int a[50][50]; int i, j; int key; int temp = 0; scanf("%d", &key); for (i = 0; i < key; i++) { for (j = 0; j < key; j++) { a[i][j] = j+i*key+1; } } for (i = 1; i < key; i++) { for (j = 0; j < key; j++) { a[i][key - j-1] = j + i*key + 1; } i++; } for (i = 0; i < key; i++) { for (j = 0; j < key; j++) { printf("%d ", a[i][j]); } puts(""); } } | 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 35 36 37 38 39 | #include <stdio.h> int main(void) { int a[50][50]; int i, j; int key; int temp = 0; scanf("%d", &key); for (i = 0; i < key; i++) { for (j = 0; j < key; j++) { a[j][i] = j+i*key+1; } } for (i = 1; i < key; i++) { for (j = key-1; j >= 0; j--) { a[key-j-1][i] = j + i * key + 1; } i++; } for (i = 0; i < key; i++) { for (j = 0; j < key; j++) { printf("%d ", a[i][j]); } puts(""); } } | cs |
다차원배열5
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 35 36 37 38 39 40 41 42 43 | #include <stdio.h> int main(void) { char a[200] = { 0, }; int i; int key; int count; int temp; scanf("%d", &key); getchar(); gets_s(a, sizeof(a)); int dcount = 0; if (key % 3 == 0) { count = key / 3 - 1; } else count = key / 3; temp = 1; for (i = key-1; i >= 0; i--, temp++) { printf("%c", a[key-i-1]); if (key >= 4 && i%3==0 && temp != 0) { if (dcount == count) { temp = 0; } else { dcount++; printf(","); } } } } | 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <stdio.h> int main(void) { int a[50][50] = { 0, }; int key; int i = 0; int j = -1; int p; int direction = 1; int d = 1; int temp; scanf("%d", &key); temp = key; while (1) { for (p = 0; p < key; p++) { j += direction; a[i][j] = d; d++; } key--; if (key <= 0) break; for (p = 0; p < key; p++) { i += direction; a[i][j] = d; d++; } direction *= -1; } for (i = 0; i < temp; i++) { for (j = 0; j < temp; j++) { printf("%d ", a[i][j]); } puts(""); } } |