Advertisement
ilyaaaaa

laba 6 var 9B

Nov 20th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<math.h>
  4. using namespace std;
  5.  
  6. void vivod(double, double, double);
  7. double func(double);
  8. double sum(int*,double, double);
  9.  
  10.  
  11.  
  12. int main()
  13. {
  14.     double a = -0.1, b = 1.3 , eps=0.001;
  15.    
  16.     vivod(a, b, eps);
  17.  
  18.     return 0;
  19. }
  20.  
  21.  
  22. void vivod(double a, double b, double eps)
  23. {
  24.     double h = (b - a) / 10;
  25.     int k = 0;
  26.     for (double x = a; x < b + h / 2; x += h)
  27.     {
  28.         cout << "x=" << x << setw(10) << "func=" << func(x) << setw(10) << "sum=" << sum(&k, x, eps) <<setw(10)<<"kolvo= "<<k<< endl;
  29.     }
  30.    
  31. }
  32.  
  33. double func(double x)
  34. {
  35.     return pow(2,x);
  36. }
  37.  
  38. double sum(int *pk,double x, double eps)
  39. {
  40.     double sum = 1, temp = 1;
  41.     double m = log(2);
  42.     double kolvo=0;
  43.     for ((*pk)=1; temp >= eps; (*pk)++)
  44.     {
  45.         kolvo++;
  46.         temp *= x * m / (*pk);
  47.         sum += temp;
  48.        
  49.     }
  50.  
  51.     return sum;
  52.    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement