Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main() {
- float pi = 0, absadd, precision, add, middle, end_pi;
- int n, i = -1;
- printf("Enter number of digits (1-7): ");
- scanf("%d", &n);
- precision = pow(0.1, n);
- do
- {
- i++;
- add = 4*pow(-1, i)/(2*i+1);
- pi += add;
- absadd = fabs(add);
- } while (absadd>=precision);
- middle = -(add/2);
- printf("step %d\n",i);
- pi += middle;
- end_pi = (float)(((int)(pi*pow(10,n)))/pow(10,n));
- printf(" pi = %.*f\n\n",n,end_pi);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement