fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double suma(double x,unsigned n)
  5. {
  6. if((fabs(x)>=1)||(n<1)) return 0;
  7. double item=x,sum=item;
  8. for(unsigned i=2,p=1;i<=n;++i,p+=2,sum+=item) item*=-x*x*p*p/((p+1)*(p+2));
  9. return sum;
  10. }
  11.  
  12. int main(void)
  13. {
  14. for(unsigned n=0;n<=4;++n) printf("%u %.12lf\n",n,suma(0.1,n));
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
0 0.000000000000
1 0.100000000000
2 0.099833333333
3 0.099834083333
4 0.099834078869