Files
BUT2/SCR/SCR3.1/TP04/pi.c
2025-11-07 15:21:24 +01:00

37 lines
573 B
C

#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;
void onAlarmSent(double pi, uint64_t shots) {
printf("Pi value = %f, Shots value = %lu", pi, shots);
}
int main(int argc,char * argv[])
{
double x,y;
t1 = tstamp();
set_signal_handler(SIGALRM, onAlarmSent);
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 ++;
}
}