U E D R , A S I H C RSS

알고리즘5주숙제/하기웅

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