24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 506  |  回复: 1
【奖励】 本帖被评价1次,作者argo增加金币 0.5
当前主题已经存档。

argo

铁杆木虫 (著名写手)


[资源] 【转贴】《蒙卡入门篇》的程序代码

原贴在:
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       x = (double)rand()/RAND_MAX;
      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 ]
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Delphi001

铜虫 (小有名气)


★★★ 三星级,支持鼓励

好像编译不能通过,不过还是可以参考,谢谢
2楼2009-03-11 17:13:20
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 argo 的主题更新
☆ 无星级 ★ 一星级 ★★★ 三星级 ★★★★★ 五星级
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 070300化学354求调剂 +4 101次希望 2026-03-28 4/200 2026-03-29 06:19 by 松花缸1201
[考研] 300求调剂,材料科学英一数二 +8 leaflight 2026-03-24 8/400 2026-03-29 01:31 by fmesaito
[考研] 071000生物学求调剂,初试成绩343 +7 小小甜面团 2026-03-25 7/350 2026-03-28 20:25 by 唐沐儿
[考研] 346求调剂 一志愿070303有机化学 +3 萝卜炖青菜 2026-03-28 3/150 2026-03-28 14:11 by 唐沐儿
[考研] 304求调剂 +6 曼殊2266 2026-03-27 6/300 2026-03-28 14:10 by 唐沐儿
[考研] 求调剂 +6 芦lty 2026-03-25 7/350 2026-03-28 13:13 by 唐沐儿
[考研] 308求调剂 +7 墨墨漠 2026-03-27 7/350 2026-03-28 07:43 by 热情沙漠
[考研] 085404求调剂,总分309,本科经历较为丰富 +4 来财aa 2026-03-25 4/200 2026-03-28 07:41 by 棒棒球手
[考研] 0703化学求调剂,各位老师看看我!!! +5 祁祺祺 2026-03-25 5/250 2026-03-27 21:44 by 东方猪猪
[考研] 07化学280分求调剂 +10 722865 2026-03-23 10/500 2026-03-27 15:51 by Plutoqq
[考研] 304材料求调剂 +4 钟llll 2026-03-26 4/200 2026-03-27 03:42 by wxiongid
[考研] 325求调剂 +3 Aoyijiang 2026-03-23 3/150 2026-03-26 20:46 by 不吃魚的貓
[考研] 085602化学工程求调剂。 +4 平乐乐乐 2026-03-26 4/200 2026-03-26 17:57 by fmesaito
[考研] 总分293求调剂 +6 加一一九 2026-03-25 8/400 2026-03-26 13:30 by yujianx
[考研] 求b区院校调剂 +4 周56 2026-03-24 5/250 2026-03-25 17:12 by yishunmin
[考研] 求调剂 +3 李李不服输 2026-03-25 3/150 2026-03-25 13:03 by cmz0325
[考研] 293求调剂 +7 加一一九 2026-03-24 7/350 2026-03-25 12:02 by userper
[考研] 材料考研调剂生 +3 黄粱一梦千年 2026-03-24 3/150 2026-03-24 17:00 by barlinike
[考研] 284求调剂 +3 yanzhixue111 2026-03-23 6/300 2026-03-23 22:58 by pswait
[考研] 361求调剂 +3 Glack 2026-03-22 3/150 2026-03-23 22:03 by fuyu_
信息提示
请填处理意见