MCPcopy Create free account
hub / github.com/E869120/math-algorithm-book / main

Function main

codes/cpp/Code_3_05_1.cpp:4–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4int main() {
5 int N = 10000; // N �͎��s�񐔁i�K�X�ύX����j
6 int M = 0;
7 for (int i = 1; i <= N; i++) {
8 double px = rand() / (double)RAND_MAX; // 0 �ȏ� 1 �ȉ��̗����i�����_���Ȑ��j�𐶐�
9 double py = rand() / (double)RAND_MAX; // 0 �ȏ� 1 �ȉ��̗����i�����_���Ȑ��j�𐶐�
10 // ���_����̋����� sqrt(px * px + py * py)
11 // ���ꂪ 1 �ȉ��ł���Ηǂ��̂ŁA�����́upx * px + py * py <= 1�v
12 if (px * px + py * py <= 1.0) M += 1;
13 }
14 printf("%.12lf\n", 4.0 * M / N);
15 return 0;
16}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected