Ответ:
#include <iostream>
#include <iomanip>
int main()
{
const double eps = 0.00001;
double x, x0, xk, h, a, s;
int n, i, k;
setlocale(LC_ALL, "Russian");
std::cout << "Введите x0: ";
std::cin >> x0;
std::cout << "Введите xk: ";
std::cin >> xk;
h = 0.1;
x = x0 - h;
n = round((xk - x0) / h) + 1;
std::cout << "№ x S(x) y(x)" << std::endl;
for (i = 0; i < n; i++)
x += h;
a = 1; s = a; k = 0;
while (abs(a) > eps)
a = -a * 2 * x / (2.0 * k + 1) / (2.0 * k + 2);
s += a;
k++;
}
std::cout << i << std::setw(5);
std::cout << x << std::setprecision(5) << std::setw(12);
std::cout << s << std::setprecision(5) << std::setw(12);
std::cout << cos(sqrt(2 * x)) << std::setprecision(5) << std::endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
#include <iostream>
#include <iomanip>
int main()
{
const double eps = 0.00001;
double x, x0, xk, h, a, s;
int n, i, k;
setlocale(LC_ALL, "Russian");
std::cout << "Введите x0: ";
std::cin >> x0;
std::cout << "Введите xk: ";
std::cin >> xk;
h = 0.1;
x = x0 - h;
n = round((xk - x0) / h) + 1;
std::cout << "№ x S(x) y(x)" << std::endl;
for (i = 0; i < n; i++)
{
x += h;
a = 1; s = a; k = 0;
while (abs(a) > eps)
{
a = -a * 2 * x / (2.0 * k + 1) / (2.0 * k + 2);
s += a;
k++;
}
std::cout << i << std::setw(5);
std::cout << x << std::setprecision(5) << std::setw(12);
std::cout << s << std::setprecision(5) << std::setw(12);
std::cout << cos(sqrt(2 * x)) << std::setprecision(5) << std::endl;
}
return 0;
}