U E D R , A S I H C RSS

알고리즘5주숙제/김상섭

~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;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:21
Processing time 0.0120 sec