主题:C语言 门特卡罗法求圆周率 帮忙修改下
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#define N 30000
main()
{
float x,y;
int c=0,d=0;
srand(time(0));
while(c++<=N)
{x=rand()/(double)RAND_MAX;
y=rand()/(double)RAND_MAX;
if(x*x+y*y<=1)
d++;
}
printf("pi=%f\n",4*d/N);
}
#include<time.h>
#include<stdio.h>
#define N 30000
main()
{
float x,y;
int c=0,d=0;
srand(time(0));
while(c++<=N)
{x=rand()/(double)RAND_MAX;
y=rand()/(double)RAND_MAX;
if(x*x+y*y<=1)
d++;
}
printf("pi=%f\n",4*d/N);
}