Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

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

From ZeroWiki
Revision as of 05:30, 7 February 2021 by imported>Unknown
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
#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;
}