> 数学 >
使用Monte Carlo 方法计算圆周率pi,写出算法和伪代码
人气:448 ℃ 时间:2020-01-31 17:33:11
解答
#include
#include
#include
double PI()
{
\x09int total,in=0,k;
\x09double x,y,x2,y2,pi;
\x09printf("输入投点总数:");
\x09scanf("%d",&total);
\x09srand((unsigned)time(NULL));
\x09for(k = 0; k < total; k++)
\x09{
\x09\x09x = (double)rand()/(RAND_MAX);
\x09\x09y = (double)rand()/(RAND_MAX);
\x09\x09x2 = pow(x-0.5 ,2);
\x09\x09y2 = pow(y-0.5 ,2);
\x09\x09if((x2 + y2)
推荐
猜你喜欢
© 2025 79432.Com All Rights Reserved.
电脑版|手机版