Advertisement
luizaspan

Cálculo de pi pelo Produto de Wallis

May 21st, 2015
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define pi M_PI
  5.  
  6. int main(void)
  7. {
  8. int n;
  9. double p,e;
  10.  
  11. p=1;
  12.  
  13. for (n=1;n<10000;n++)
  14. {
  15. p*=(2.*n/(2.*n-1))*(2.*n/(2.*n+1));
  16. // printf("%lf \n",p);
  17. }
  18.  
  19. e=((pi/2)-p)/(pi/2);
  20. printf("\nValor real: %lf \n",pi/2);
  21. printf("Valor calculado pela fórmula de Wallis: %lf \n",p);
  22. printf("Erro relativo: %lf \n\n",e);
  23.  
  24.  
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement