Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- #include<math.h>
- using namespace std;
- void vivod(double, double, double);
- double func(double);
- double sum(int*,double, double);
- int main()
- {
- double a = -0.1, b = 1.3 , eps=0.001;
- vivod(a, b, eps);
- return 0;
- }
- void vivod(double a, double b, double eps)
- {
- double h = (b - a) / 10;
- int k = 0;
- for (double x = a; x < b + h / 2; x += h)
- {
- cout << "x=" << x << setw(10) << "func=" << func(x) << setw(10) << "sum=" << sum(&k, x, eps) <<setw(10)<<"kolvo= "<<k<< endl;
- }
- }
- double func(double x)
- {
- return pow(2,x);
- }
- double sum(int *pk,double x, double eps)
- {
- double sum = 1, temp = 1;
- double m = log(2);
- double kolvo=0;
- for ((*pk)=1; temp >= eps; (*pk)++)
- {
- kolvo++;
- temp *= x * m / (*pk);
- sum += temp;
- }
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement