回答編集履歴
2
最小限の修正の追加
test
CHANGED
@@ -241,3 +241,75 @@
|
|
241
241
|
|
242
242
|
|
243
243
|
```
|
244
|
+
|
245
|
+
# 追記(最小限の修正)
|
246
|
+
|
247
|
+
ご質問のコードだと、平行線の間隔が1, 棒の長さが0.5になりますね。
|
248
|
+
|
249
|
+
```C
|
250
|
+
|
251
|
+
#include <math.h>
|
252
|
+
|
253
|
+
#include <stdio.h>
|
254
|
+
|
255
|
+
#include <stdlib.h>
|
256
|
+
|
257
|
+
#include <time.h>
|
258
|
+
|
259
|
+
#define pi 3.141592
|
260
|
+
|
261
|
+
int main(void)
|
262
|
+
|
263
|
+
{
|
264
|
+
|
265
|
+
int m = 1000;
|
266
|
+
|
267
|
+
int i, j;
|
268
|
+
|
269
|
+
srand((unsigned int)time(NULL));
|
270
|
+
|
271
|
+
int randam[5][1000] = { 0 };
|
272
|
+
|
273
|
+
for (i = 0; i < 5; i++) {
|
274
|
+
|
275
|
+
for (j = 0; j < m; j++) {
|
276
|
+
|
277
|
+
randam[i][j] = rand();
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
for (i = 0; i < 5; i++) {
|
286
|
+
|
287
|
+
int num = 0;
|
288
|
+
|
289
|
+
for (j = 0; j < m; j++) {
|
290
|
+
|
291
|
+
double x, y;
|
292
|
+
|
293
|
+
x = (float)randam[i][j] / (RAND_MAX + 1.0); //0~1の範囲の小数点乱数
|
294
|
+
|
295
|
+
y = x + 0.5 * sin(((float)randam[i][m - j]) / (RAND_MAX + 1.0) * 2 * pi);
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
if (y <= 0 || 1 <= y) {
|
300
|
+
|
301
|
+
num++;
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
printf("result%d :%e\n", i + 1, m / (double)num);
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
return 0;
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
```
|
1
#define _USE_MATH_DEFINES追加
test
CHANGED
@@ -14,6 +14,8 @@
|
|
14
14
|
|
15
15
|
```C
|
16
16
|
|
17
|
+
#define _USE_MATH_DEFINES
|
18
|
+
|
17
19
|
#include <math.h>
|
18
20
|
|
19
21
|
#include <stdio.h>
|
@@ -110,6 +112,8 @@
|
|
110
112
|
|
111
113
|
```C
|
112
114
|
|
115
|
+
#define _USE_MATH_DEFINES
|
116
|
+
|
113
117
|
#include <math.h>
|
114
118
|
|
115
119
|
#include <stdio.h>
|