Guest User

Untitled

a guest
Apr 25th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. // 5. x + x3/3! + x5/5! +…+ x2n-1/(2n-1)! (sh(x))
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. double sh(double, double, int&);
  7.  
  8. void main() {
  9.     double x = 0, eps = 0.0001;
  10.     int n = 0;
  11.     printf("x\tSh(x) from math.h\tSh(x) from custom function\n\n");
  12.     for (x = 0.1; x<1; x+=0.1) {
  13.         printf("%.2f\t", x);
  14.         printf("%.4f  \t\t", sinh(x));
  15.         printf("%.4f\n", sh(x, eps, n));
  16.     }
  17. }
  18.  
  19. double sh(double x, double eps, int &n) {
  20.     double sum = 0, cur = x;
  21.     n = 2;
  22.     while (cur >= eps) {
  23.         sum+=cur;
  24.         cur *= x*x/(4*n*n - 6*n + 3);
  25.         n++;
  26.     }
  27.     return sum;
  28. }
Add Comment
Please, Sign In to add comment