31 lines
524 B
C
31 lines
524 B
C
|
#include <assert.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdint.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/wait.h>
|
||
|
#include <signal.h>
|
||
|
|
||
|
uint64_t shots_in=0,shots=0;
|
||
|
double x,y;
|
||
|
|
||
|
void signalrm_handler(int n){
|
||
|
|
||
|
}
|
||
|
|
||
|
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*/
|
||
|
}
|