U
U
ua_human2014-12-23 17:17:44
Programming
ua_human, 2014-12-23 17:17:44

How to make a Taylor series (via pointers)?

How can you convert this code to pointers? and through the function

#include "stdafx.h"
#include <iostream>
#include <math.h>
#include "conio.h"
#include "stdio.h"

using namespace std;

int main()
{

  int  n, k, i;
  double Xn, Xe, dx, x, e = 1E-5, Fun;
  const double pi = 3.141592;

  k = 0;

  cout << ("entere Xn=");
  cin >> Xn;
  cout << ("entere Xe=");
  cin >> Xe;
  cout << ("entere dx=");
  cin >> dx;
  x = Xn;
  while (x <= Xe)
  {
    n = 0;
    double result = pi / 2;
    double sum = 0;
    double E = 0;
    k++;
    do
    {

      sum += pow(-1.0, n + 1) / ((2 * n + 1)*pow(x, 2 * n + 1));
      ++n;
      E = pow(-1.0, n + 1) / ((2 * n + 1)*pow(x, 2 * n + 1));


    } while (fabs(E) >= e);
    k++;
    Fun = atan(x);
    cout << " x = " << x << "\t atan = " << result - sum << "\t k=" << k << "\t arctg(x)=" << Fun << endl;
    x += dx;

  }
  _getch();

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bogolt, 2014-12-23
@bogolt

You have three explicit sections in your program - these are data input, calculation and output of the result. Each of these fragments can be moved into its own function.
About pointers - you can return values ​​from the input function with pointers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question