Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- float wallis(int n,float res){
- if(n<=0)
- return res*2.0;
- return (wallis(n-1,res*(((2.0*(n+1.0)))/(((((2.0*n)-1)))*(((2*n)+1))))));
- }
- int main(){
- int n,i;
- float w=1.0,cont=1.0;
- scanf("%d",&n);
- for(i=0;i<n;i++){
- w = w * (((2.0*(cont+1.0)))/(((((2.0*cont)-1)))*(((2*cont)+1))));
- cont++;
- }
- printf("o valor de pi e: %f ",w*2.0);
- //recursivamente
- printf("\n recursivamente temos: ");
- printf("%f",wallis(n,1.0));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement