fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6.  
  7. double a, b, h,n;
  8. puts("Input a, b,h ,n"); scanf("%lf%lf%lf%lf", &a, &b, &h, &n);
  9.  
  10. for(double x = a; x <= b; x += h)
  11. {
  12. double xq = x/sqrt(2);
  13. double Y = exp(xq)*cos(xq);
  14.  
  15. double cs[8] = { 1, 1/sqrt(2), 0, -1/sqrt(2) };
  16. double S = 1, t = 1;
  17. for(int k = 1; k <= n; ++k) S += cs[k%4]*(1 - 2*((k/4)%2))*(t *= x/k);
  18.  
  19. printf("%.3lf %15.7lf %15.7lf\n",x,Y,S);
  20. }
  21. }
  22.  
  23.  
Success #stdin #stdout 0s 5344KB
stdin
1 2 0.2 50
stdout
Input a, b,h ,n
1.000        1.5418635        1.5418635
1.200        1.5444381        1.5444381
1.400        1.4766921        1.4766921
1.600        1.3187595        1.3187595
1.800        1.0484356        1.0484356
2.000        0.6414355        0.6414355