回答編集履歴
1
ソース追記
test
CHANGED
@@ -1 +1,75 @@
|
|
1
1
|
Cの配列長は固定です。なので、malloc()等でメモリを確保して使いましょう。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
「追記」
|
6
|
+
|
7
|
+
```c
|
8
|
+
|
9
|
+
/**
|
10
|
+
|
11
|
+
teratail:166610
|
12
|
+
|
13
|
+
*/
|
14
|
+
|
15
|
+
#include <stdio.h>
|
16
|
+
|
17
|
+
#include <stdlib.h>
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
int main(void)
|
22
|
+
|
23
|
+
{
|
24
|
+
|
25
|
+
printf("Please diceid n(the length of an array).\n");
|
26
|
+
|
27
|
+
int yo = 0;
|
28
|
+
|
29
|
+
scanf("%d", &yo);
|
30
|
+
|
31
|
+
// int dt[yo] = { 1 };
|
32
|
+
|
33
|
+
int *dt = (int *)malloc((size_t)yo * sizeof(int));
|
34
|
+
|
35
|
+
//
|
36
|
+
|
37
|
+
for (int i = 0; i < yo; i++) {
|
38
|
+
|
39
|
+
dt[i] = i;
|
40
|
+
|
41
|
+
printf("%d\n", dt[i]);
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
free(dt);
|
46
|
+
|
47
|
+
//
|
48
|
+
|
49
|
+
return 0;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
結果
|
56
|
+
|
57
|
+
```text
|
58
|
+
|
59
|
+
usr ~/Project/test % ./a.out
|
60
|
+
|
61
|
+
Please diceid n(the length of an array).
|
62
|
+
|
63
|
+
5
|
64
|
+
|
65
|
+
0
|
66
|
+
|
67
|
+
1
|
68
|
+
|
69
|
+
2
|
70
|
+
|
71
|
+
3
|
72
|
+
|
73
|
+
4
|
74
|
+
|
75
|
+
```
|