#include <locale>
#include <iostream>
#include <iomanip>
#include <valarray>
#include <vector>
using namespace std;
// Заданная функция
double y(double x)
{
return x*x/sin(5*x);
}
int main()
{
locale::global(locale("rus_rus.866"));
double A,B,h;
vector<double> plus,minus;
// Ввод исходных данных
wcout<<L"Введите нижний предел A:";
wcin>>A;
wcout<<L"Введите верхний предел B:";
wcin>>B;
wcout<<L"Введите шаг h:";
wcin>>h;
wcout<<L"---------------------------"<<endl;
wcout<<L"| x | y |"<<endl;
wcout<<L"---------------------------"<<endl;
// Вывод результата
for(double x=A;x<=B;x+=h)
{
double ry=y(x);
wcout<<L'|'<<fixed<<setprecision(3)<<setw(12)<<x<<L'|'<<setw(12)<<ry<<L'|'<<endl;
// Заносим положительные в plus, отрицательные в minus
if(ry>0)plus.push_back(ry);
else if(ry<0)minus.push_back(ry);
}
wcout<<L"---------------------------"<<endl;
// Выводим массивы plus и minus
wcout<<L"Массив plus:"<<endl;
wcout<<L'{';
for(vector<double>::iterator it=plus.begin();it!=plus.end();it++)
wcout<<*it<<L',';
if(plus.size())wcout<<L'\b';
wcout<<L'}'<<endl;
wcout<<L"---------------------------"<<endl;
wcout<<L"Массив minus:"<<endl;
wcout<<L'{';
for(vector<double>::iterator it=minus.begin();it!=minus.end();it++)
wcout<<*it<<L',';
if(minus.size())wcout<<L'\b';
wcout<<L'}'<<endl;
wcout<<L"---------------------------"<<endl;
system("PAUSE");
return 0;
}
Введите нижний предел A:5
Введите верхний предел B:10
Введите шаг h:0.4
---------------------------
| x | y |
---------------------------
| 5.000| -188.891|
| 5.400| 30.490|
| 5.800| -50.691|
| 6.200| -95.140|
| 6.600| 43.564|
| 7.000| -114.437|
| 7.400| -85.092|
| 7.800| 63.125|
| 8.200| -423.899|
| 8.600| -88.918|
| 9.000| 95.193|
| 9.400| 715.042|
| 9.800| -100.697|
---------------------------
Массив plus:
{30.490,43.564,63.125,95.193,715.042}
---------------------------
Массив minus:
{-188.891,-50.691,-95.140,-114.437,-85.092,-423.899,-88.918,-100.697}
---------------------------
#include <locale>
#include <iostream>
#include <iomanip>
#include <valarray>
#include <vector>
using namespace std;
// Заданная функция
double y(double x)
{
return x*x/sin(5*x);
}
int main()
{
locale::global(locale("rus_rus.866"));
double A,B,h;
vector<double> plus,minus;
// Ввод исходных данных
wcout<<L"Введите нижний предел A:";
wcin>>A;
wcout<<L"Введите верхний предел B:";
wcin>>B;
wcout<<L"Введите шаг h:";
wcin>>h;
wcout<<L"---------------------------"<<endl;
wcout<<L"| x | y |"<<endl;
wcout<<L"---------------------------"<<endl;
// Вывод результата
for(double x=A;x<=B;x+=h)
{
double ry=y(x);
wcout<<L'|'<<fixed<<setprecision(3)<<setw(12)<<x<<L'|'<<setw(12)<<ry<<L'|'<<endl;
// Заносим положительные в plus, отрицательные в minus
if(ry>0)plus.push_back(ry);
else if(ry<0)minus.push_back(ry);
}
wcout<<L"---------------------------"<<endl;
// Выводим массивы plus и minus
wcout<<L"Массив plus:"<<endl;
wcout<<L'{';
for(vector<double>::iterator it=plus.begin();it!=plus.end();it++)
wcout<<*it<<L',';
if(plus.size())wcout<<L'\b';
wcout<<L'}'<<endl;
wcout<<L"---------------------------"<<endl;
wcout<<L"Массив minus:"<<endl;
wcout<<L'{';
for(vector<double>::iterator it=minus.begin();it!=minus.end();it++)
wcout<<*it<<L',';
if(minus.size())wcout<<L'\b';
wcout<<L'}'<<endl;
wcout<<L"---------------------------"<<endl;
system("PAUSE");
return 0;
}
Введите нижний предел A:5
Введите верхний предел B:10
Введите шаг h:0.4
---------------------------
| x | y |
---------------------------
| 5.000| -188.891|
| 5.400| 30.490|
| 5.800| -50.691|
| 6.200| -95.140|
| 6.600| 43.564|
| 7.000| -114.437|
| 7.400| -85.092|
| 7.800| 63.125|
| 8.200| -423.899|
| 8.600| -88.918|
| 9.000| 95.193|
| 9.400| 715.042|
| 9.800| -100.697|
---------------------------
Массив plus:
{30.490,43.564,63.125,95.193,715.042}
---------------------------
Массив minus:
{-188.891,-50.691,-95.140,-114.437,-85.092,-423.899,-88.918,-100.697}
---------------------------
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.