C/C++の宿題やらせてください。6代目。
■ このスレッドは過去ログ倉庫に格納されています
002523
NGNG#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int i, count;
double x, y;
srand(time(NULL));
count = 0;
for (i = 0; i < 10000; i++) {
x = (double)rand() / RAND_MAX;
y = (double)rand() / RAND_MAX;
if (x * x + y * y < 1.0) count++;
}
printf("%lf\n", (double)count / i * 4);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています