| 查看: 538 | 回复: 1 | ||
| 【奖励】 本帖被评价1次,作者argo增加金币 0.5 个 | ||
| 当前主题已经存档。 | ||
[资源]
【转贴】《蒙卡入门篇》的程序代码
|
||
|
原贴在: http://muchong.com/bbs/viewthread.php?tid=589636&fpage=1&view=&highlight=&page=1 这么小的程序代码用附件,太浪费大家的金币了。我下了,代码贴在下面,希望没有违反版规。 Example C Program to Compute PI Using A Monte Carlo Method Source code: /* Program to compute Pi using Monte Carlo methods */ #include #include #include #include #define SEED 35791246 main(int argc, char* argv) { int niter=0; double x,y; int i,count=0; /* # of points in the 1st quadrant of unit circle */ double z; double pi; printf("Enter the number of iterations used to estimate pi: " ;scanf("%d",&niter); /* initialize random numbers */ srand(SEED); count=0; for ( i=0; i y = (double)rand()/RAND_MAX; z = x*x+y*y; if (z<=1) count++; } pi=(double)count/niter*4; printf("# of trials= %d , estimate of pi is %g \n",niter,pi); } [ Last edited by sunxiao on 2009-3-10 at 05:17 ] |
» 猜你喜欢
售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急
已经有4人回复
面上没中,邀请各位路过的虫友分析一下分数
已经有7人回复
哈尔滨工业大学韩晓军教授课题组招收2027年硕士推免生及博士研究生
已经有3人回复
找导师
已经有8人回复
国社科又开始会评了,不知道这次命运如何
已经有14人回复
麻烦专家们看看评委们的意见(F口面上)
已经有13人回复
科研人应该花精力去思考如何解决问题,而不是去凝练问题
已经有14人回复
要骂人了,新模版改版就是要淡化问题凝练这种虚的东西,结果有个评委还在说凝练得不够
已经有17人回复
学科评审组评审是指会评吗?
已经有5人回复
小白求助 投论文要求的highlights应该如何写
已经有4人回复
2楼2009-03-11 17:13:20










;
回复此楼