tkt
This commit is contained in:
18
SCR3.1/TP4/Exo2/montecarlo.c
Normal file
18
SCR3.1/TP4/Exo2/montecarlo.c
Normal file
@@ -0,0 +1,18 @@
|
||||
uint64_t shots_in=0,shots=0;
|
||||
double x,y;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
shots_in = 0;
|
||||
shots = 0;
|
||||
for (;;){
|
||||
x = rand()/(RAND_MAX*1.0);
|
||||
y = rand()/(RAND_MAX*1.0);
|
||||
shots ++;
|
||||
if ((x*x+y*y)<=1){
|
||||
shots_in ++;
|
||||
}
|
||||
}
|
||||
/* la probabilité vaut tirsIn/tirs,
|
||||
Elle converge lentement vers pi/4*/
|
||||
}
|
||||
Reference in New Issue
Block a user