This is trash

This commit is contained in:
LiveEmily 2021-09-07 20:55:29 +02:00
commit e99f9ba1c9
2 changed files with 41 additions and 0 deletions

36
main.c Normal file
View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <float.h>
float pi(float n) {
int n_circle = 0;
int n_total = 0;
srand(time(NULL));
for(float i = 0; i < n; i++)
{
int x = rand() % 2;
int y = rand() % 2;
int distance = pow(x, 2) + pow(y, 2);
if(distance <= 1) {
n_circle += 1;
}
n_total += 1;
}
printf("n_circle = %d\nn_total = %d\n", n_circle, n_total);
return 4 * (float) n_circle / (float) n_total;
}
int main() {
float pi_ans = pi(pow(10, 7));
printf("pi = %f\n", pi_ans);
return 0;
}

5
makefile Normal file
View File

@ -0,0 +1,5 @@
CC=clang
CFLAGS=--pedantic --std=c99 -lm
main: main.c
$(CC) $(CFLAGS) -o pi main.c