#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;
Тут с флагами. Если не нравятся флаги - перестройте под себя.
#include <conio.h>
#include <time.h>
using namespace std;
void main()
{
srand(time(NULL));
setlocale(0, "");
int arr[17];
int a, b, chet=0, nechet = 0;
cout << "Введите диапазон ." << endl << "Нижняя граница диапазона: "; cin >> a; cout << "Верхняя граница диапазона: "; cin >> b; cout << endl;
for (int i = 0; i < 17; ++i)
{
arr[i] = a + rand() % (b-a+1);
cout <<" "<<arr[i];
}
for (int i = 0; i < 17; ++i)
{
if (arr[i] % 2 == 0) chet++;
else nechet++;
} if (chet > nechet)
cout << " \n Четных больше";
else if (nechet>chet)
cout << "\n Нечетных больше";
else cout << "\n Одинаковое количество четных и нечетных";
_getch();
}
#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;
}
Тут с флагами. Если не нравятся флаги - перестройте под себя.