#include "pch.h"
#include
using namespace std;
double f(double x)
{
double m = -7 * pow(x, 3) - 5.8*x - 4;
return m;
}
int main()
double a = -1; double b = 2;
flag1:
double c = 0.5*(a + b);
if (f(c) == 0)
cout << "The result is " << c << endl;
if (f(c)*f(a) < 0)
b = c;
goto flag1;
if (f(c)*f(b) < 0)
a = c;
if (c >= a && c <= b)
cout << "The solution belongs to the interval" << endl;
else
cout << "The solution doesn't belongs to the interval";
return 0;
Тут с флагами. Если не нравятся флаги - перестройте под себя.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include "pch.h"
#include
#include
using namespace std;
double f(double x)
{
double m = -7 * pow(x, 3) - 5.8*x - 4;
return m;
}
int main()
{
double a = -1; double b = 2;
flag1:
double c = 0.5*(a + b);
if (f(c) == 0)
cout << "The result is " << c << endl;
if (f(c)*f(a) < 0)
{
b = c;
goto flag1;
}
if (f(c)*f(b) < 0)
{
a = c;
goto flag1;
}
if (c >= a && c <= b)
cout << "The solution belongs to the interval" << endl;
else
cout << "The solution doesn't belongs to the interval";
return 0;
}
Тут с флагами. Если не нравятся флаги - перестройте под себя.