C/C++

Помогите написать код решения уравнения, желательно на с++

Sin(x^2) + x^2 = 0,5
#include <iostream>
#include <iomanip>
using namespace std;
auto equation(double n) {
if (!n) return make_pair(n, n);
if (n < 0) return make_pair(n / 0, n / 0);
auto x = n;
double y, dx;
auto less = true;
auto greater = true;
auto iter = 0;
const auto eps = 1e-15;
const auto lim = 0x100'0000;
const auto ten = 10;
do {
y = sin(x * x) + x * x;
if (fabs(y - n) < eps) break;
if (less && y < n) {
dx = (n - y) / ten;
less = false;
greater = true;
}
if (greater && y > n) {
dx = (n - y) / ten;
greater = false;
less = true;
}
x += dx;
} while (++iter < lim);
return make_pair(x, -x);
}
int main() {
auto [x1, x2] = equation(0.5);
cout << fixed << setprecision(15)
<< "x1 = " << x1 << '\n'
<< "x2 = " << x2 << '\n';
system("pause > nul");
}
Кирилл Пылков
Кирилл Пылков
71 338
Лучший ответ
Наслаждайся :D
#include //iostream
#include //cmath

int main()
{
double x = 0.0;

while (sin(x*x) + x * x < 0.5)
x += 0.000001;

std::cout << x << " " << x * (-1.0) << std::endl;
}