axeefectushka

Untitled

Jan 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5. void tabl(double *, double *, double *);
  6. double sum(double *, double *, int *);
  7.  
  8. int main1()
  9. {
  10.     double a = -0.9, b = 0.9, eps = 0.0001;
  11.     cout << "\t\t" << "x" << "\t\t" << "F(x)" << "\t\t\t" << "sum" << "\t\t\t" << "n" << endl;
  12.     tabl(&a,&b,&eps);
  13.     system("pause");
  14.     return 0;
  15. }
  16.  
  17. void tabl(double *a, double *b, double *eps)
  18. {
  19.     int n=0;
  20.     for (double x = *a; x < *b; x += (*b - *a) / 10)
  21.     {
  22.         cout << "\t\t" << x << "\t\t" << cos(x - 4) << "\t\t" << sum(&x, eps, &n);
  23.         cout << "\t\t" << n << endl;
  24.     }
  25. }
  26.  
  27. double sum(double *x, double *eps, int *n)
  28. {
  29.     double s = 0, chis = 1, znam = 1;
  30.     *n = 0;
  31.     while (fabs(chis/znam)>*eps)
  32.     {
  33.         s += chis / znam;
  34.         *n += 1;
  35.         chis *= (-(4 - *x)*(4 - *x));
  36.         znam *= 2 * (*n)*(2 * (*n) - 1);
  37.  
  38.     }
  39.     return s;
  40. }
Add Comment
Please, Sign In to add comment