Hello I am trying to make a programm to calculate pi through Gottfried Leibniz formula (1-(1/3)+(1/5)-(1/7)+(1/9)...)=pi/4
I must make 4 threads. The first will calculate the formula for i=1 to 1000 the second 1000 to 2000 3rd 2000-3000 & 4th 3000-4000. I dont know how to use the count function connect each thread result and then sum it in order to calculate pi dividing by 4.
Here is the code I have made so far.
Thanks in Advance!
P.S. I want some hints not the solution. How to use count function and how to sum thread results.
I must make 4 threads. The first will calculate the formula for i=1 to 1000 the second 1000 to 2000 3rd 2000-3000 & 4th 3000-4000. I dont know how to use the count function connect each thread result and then sum it in order to calculate pi dividing by 4.
Here is the code I have made so far.
int main() { pthread_t t1,t2,t3,t4; (pthread_create(&t1,NULL,(void *)&count,"th1") { exit(1); } return 0; } void count(void *str) { float denominator = 1.0; int sign = 1; float sum = 0; int i,j; for(j=i; j < i; j++) { sum += sign / denominator; sign = -sign; denominator += 2; } }
Thanks in Advance!
P.S. I want some hints not the solution. How to use count function and how to sum thread results.