Advertisement
JewishCat

25v.teilor

May 23rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cassert>
  4. using namespace std; // используем пространство имен std
  5.  
  6. std::int32_t fac(std::int32_t x) {
  7.     static const int table[] = {
  8.         1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600,
  9.     };
  10.     assert(x >= 0);
  11.     assert(x <= 12);
  12.     return table[x];
  13. }
  14.  
  15. int main(int argc, const char * argv[]) {
  16.     // insert code here...
  17.     float sum = 0;
  18.     float x = 1;
  19.     float y = sin(pow(x,3)) - x; // = -0.158529
  20.     cout << "Library's value: sin (x^3) - 1 = " << y <<endl;
  21.     double n = 0;
  22.     int i = 1;
  23.     do{
  24.         sum += n;
  25.         n = (pow(-1, i)* pow(x, 2*i+1))/(fac(2*i+1));
  26.         i++;
  27.     } while (fabs(n) > 0.0001);
  28.     cout << "Approximate value with Taylor series = "<< sum << endl;
  29.     system("pause");
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement