Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 5. x + x3/3! + x5/5! +…+ x2n-1/(2n-1)! (sh(x))
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- double sh(double, double, int&);
- void main() {
- double x = 0, eps = 0.0001;
- int n = 0;
- printf("x\tSh(x) from math.h\tSh(x) from custom function\n\n");
- for (x = 0.1; x<1; x+=0.1) {
- printf("%.2f\t", x);
- printf("%.4f \t\t", sinh(x));
- printf("%.4f\n", sh(x, eps, n));
- }
- }
- double sh(double x, double eps, int &n) {
- double sum = 0, cur = x;
- n = 2;
- while (cur >= eps) {
- sum+=cur;
- cur *= x*x/(4*n*n - 6*n + 3);
- n++;
- }
- return sum;
- }
Add Comment
Please, Sign In to add comment