~cpp
#include <iostream>
#include <time.h>
#include <math.h>
using namespace std;
unsigned int max = 1000000;
int main()
{
	double x, y;
	int count = 0;
	srand(time(NULL));
	for(int i = 0; i < max; i++)
	{
		x = rand();
		y = rand();
		x = x/RAND_MAX;
		y = y/RAND_MAX;
		if(sqrt(x*x + y*y) <= 1)
//		cout << x << "  " << y << endl;
			count++;
	}

	cout << 4*(double)count/max << endl;
	
	return 0;
}
Retrieved from http://wiki.zeropage.org/wiki.php/알고리즘5주숙제/김상섭
last modified 2021-02-07 05:30:21