Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <math.h>
- #include <iomanip.h>
- typedef double (*uf)(double,double,int &);
- void table(double,double,double,double, uf);
- double y(double,double,int &);
- double s(double,double,int &);
- int main()
- {
- cout << setw(8) << "x"<< setw(15) << "y(x)" << setw(10) <<"k" << endl;
- table(-1,1,0.1,0.001,y);
- cout << endl;
- cout << setw(8) << "x"<< setw(15) << "s(x)" << setw(10) <<"k" << endl;
- table(-1,1,0.1,0.001,s);
- return 0;
- }
- void table(double a,double b,double h,double eps,uf fun )
- {
- int k=0;
- double sum;
- for (double x=a; x<=b+h/2; x+=h)
- {
- sum=fun(x,eps,k);
- cout << setw(8) << x << setw(15) << sum << setw(10) <<k << endl;
- }
- }
- double y(double x, double eps, int &k)
- {
- return -x+asin(x);
- }
- double s(double x, double eps, int &k)
- {
- double a,c,sum;
- sum=a=c=x;
- k=1;
- while (fabs(c)>eps)
- {
- c=pow(x,2)*(2*k-1)/(2*k*(2*k+1));
- a*=c;
- sum+=a;
- k++;
- }
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement