Question
Fill in the blanks to the code to make it work
One formula to calculate the approximate value of pi is given below: y = 1/2 + (1/2 * 3/4) + (1/2 * 3/4 * 5/6) + (1/2 * 3/4 * 5/6 * 7/8) + (Xi * 2 * (i + 1) - 1 / 2 * (i + 1) if Xi+1 = Xi * The code below is developed based on the formula, and it continue on adding until the last item is smaller than 10-5. Fill the blanks to make the code work. #include int main() { doble s = 0, t = 0.5; int n; for (___; t>=le-2;n++) { s=s+t; ___ } printf("y=%f ",___); return 0; }
Explanation / Answer
int t1 = 1
for (t = t1*t;t>=1e-2;n++) // to perform t = 1/2*3/4
{
s = s+t;
t1 = t;
t = (2*n - 1)/2*n;// n is number of terms
}