Hi, this is the algorithm to calculate pi,
Pi = 4-4/3+4/5-4/7+4/9...= 4*((-1)^n+1)/2n-1
It's very similar to your need
#include<stdio.h>
#include<math.h>
int main()
{
float delta; //precision
float pi=0,temp;
int n=1;
scanf("%f",&delta);
do
{
temp = (pow(-1.0,n+1)/(2*n-1)*4);
pi+=temp;
n+=1;
if (temp<0)
temp*=-1;
}while (temp>delta);
printf("%f",pi);
return 0;
}
I hope I helped you
BTW… the delta must be les then zero