~cpp
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

#define testcase 100000000

int main()
{
	int i = testcase;
	double x, y, length;
	int number=0;
	srand(time(NULL));

	while(i--)
	{
		x= (double)rand()/RAND_MAX;
		y= (double)rand()/RAND_MAX;
		length = sqrt(x*x+y*y);
		if(length<=1)
			number++;
	}
	double pi = 4.0*number/testcase; 
	cout << pi <<endl;
	return 0;
}
Retrieved from http://wiki.zeropage.org/wiki.php/알고리즘5주숙제/하기웅
last modified 2021-02-07 05:30:20