Advertisement
Caneq

lb2.2.8

Oct 29th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. // 2.2.8.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #define _USE_MATH_DEFINES
  7. #include <math.h>  
  8.  
  9. using namespace std;
  10.  
  11. double fact(double x) {
  12.     int fact = 1;
  13.     for (int i = 1; i <= x; i++) {
  14.         fact *= i;
  15.     }
  16.     return fact;
  17. }
  18.  
  19. int main()
  20. {
  21.     setlocale(LC_ALL, "rus");
  22.     cout << "С помощью встроенных функций | С помощью ряда Тейлора" << endl;
  23.     double x0 = 0, xn = 2 * M_PI;
  24.     int i = 0;
  25.     double x = 0;
  26.     while (x <= xn) {
  27.         x = x0 + i*0.1;
  28.         cout << cos(x) + sin(x) << " | ";
  29.         double cosxt = 1;
  30.         for (int i = 1; i <= 6; i++) {
  31.             cosxt += pow(-1,i) * pow(x, i*2) / fact(i*2);
  32.         }
  33.         double sinxt = x;
  34.         for (int i = 1; i <= 6; i++) {
  35.             sinxt += pow(-1, i) * pow(x, i * 2 + 1) / fact(i * 2 + 1);
  36.         }
  37.         double xt = cosxt + sinxt;
  38.         cout << xt << endl;
  39.         i++;
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement