Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 2.2.8.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #define _USE_MATH_DEFINES
- #include <math.h>
- using namespace std;
- double fact(double x) {
- int fact = 1;
- for (int i = 1; i <= x; i++) {
- fact *= i;
- }
- return fact;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- cout << "С помощью встроенных функций | С помощью ряда Тейлора" << endl;
- double x0 = 0, xn = 2 * M_PI;
- int i = 0;
- double x = 0;
- while (x <= xn) {
- x = x0 + i*0.1;
- cout << cos(x) + sin(x) << " | ";
- double cosxt = 1;
- for (int i = 1; i <= 6; i++) {
- cosxt += pow(-1,i) * pow(x, i*2) / fact(i*2);
- }
- double sinxt = x;
- for (int i = 1; i <= 6; i++) {
- sinxt += pow(-1, i) * pow(x, i * 2 + 1) / fact(i * 2 + 1);
- }
- double xt = cosxt + sinxt;
- cout << xt << endl;
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement