Home Forums C Programming Approximate the value of PI Reply To: Approximate the value of PI

#3446
glimpse
Participant

I don’t understand so much from mathemics, but a problem migth be, that your variable i is an integer value.
Something else: What should happen, if (i%2==1) ?
I expect you mean the hole part:


if (sum%2==0)
sum=sum+1/y;
else    sum=sum-1/y;
//The I would put this part into brackets {}.if (i%2==1){   
if (sum%2==0)
        sum=sum+1/y;

    else
        sum=sum-1/y;orif (i%2==1)
    if (sum%2==0)
        sum=sum+1/y;else    sum=sum-1/y;