Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <cassert>
- using namespace std; // используем пространство имен std
- std::int32_t fac(std::int32_t x) {
- static const int table[] = {
- 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600,
- };
- assert(x >= 0);
- assert(x <= 12);
- return table[x];
- }
- int main(int argc, const char * argv[]) {
- // insert code here...
- float sum = 0;
- float x = 1;
- float y = sin(pow(x,3)) - x; // = -0.158529
- cout << "Library's value: sin (x^3) - 1 = " << y <<endl;
- double n = 0;
- int i = 1;
- do{
- sum += n;
- n = (pow(-1, i)* pow(x, 2*i+1))/(fac(2*i+1));
- i++;
- } while (fabs(n) > 0.0001);
- cout << "Approximate value with Taylor series = "<< sum << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement