tsounakis

Plouffe calculation of π in C Lang

Apr 5th, 2021 (edited)
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(){
  5.     int n = 1000, i, a;
  6.     double Pi = 0.0;
  7.  
  8.     /* case a */
  9.     for (i=0;i<n;i++){
  10.         Pi += (4.0/(8.0*i+1.0)-2/(8.0*i+4.0)-1.0/(8.0*i+5.0)-1.0/(8.0*i+6.0))/pow(16.0,i);
  11.     }
  12.     printf("Pi = %f", Pi);
  13.     /*end of case a*/
  14.  
  15.     /* case b
  16.     printf("Specify a number \'a\'.\n");
  17.     scanf("%d", &a);
  18.     for (i=0;i<a;i++){
  19.         Pi += (4.0/(8.0*i+1.0)-2/(8.0*i+4.0)-1.0/(8.0*i+5.0)-1.0/(8.0*i+6.0))/pow(16.0,i);
  20.     }
  21.     printf("\nPi = %f", Pi);
  22.     end of case b*/
  23.  
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment