BUT2/SCR/SCR2/TP04/pi.c

32 lines
425 B
C
Raw Normal View History

2023-10-12 16:39:49 +02:00
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include<stdint.h>
#include<assert.h>
#include "helpers.h"
uint64_t shots = 0,
shots_in = 0;
double pi = 0,
t1;
int main(int argc,char * argv[])
{
double x,y;
t1 = tstamp();
alarm(5);
while(1){
x = ((double)rand())/(double)RAND_MAX;
y = ((double)rand())/(double)RAND_MAX;
shots ++;
if ((x*x+y*y) <= 1)
shots_in ++;
}
}