Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include<stdio.h>
  2. float wallis(int n,float res){
  3. if(n<=0)
  4. return res*2.0;
  5.  
  6. return (wallis(n-1,res*(((2.0*(n+1.0)))/(((((2.0*n)-1)))*(((2*n)+1))))));
  7. }
  8. int main(){
  9. int n,i;
  10. float w=1.0,cont=1.0;
  11. scanf("%d",&n);
  12. for(i=0;i<n;i++){
  13. w = w * (((2.0*(cont+1.0)))/(((((2.0*cont)-1)))*(((2*cont)+1))));
  14. cont++;
  15. }
  16.  
  17. printf("o valor de pi e: %f ",w*2.0);
  18. //recursivamente
  19. printf("\n recursivamente temos: ");
  20. printf("%f",wallis(n,1.0));
  21. return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement