Обчислити 30 значень функції y=ax^2+bx+c на відрізку [e,f], зберегти їх в масив Y. Негативні компоненти масиву Y скопіювати в масив Ynegative, а позитивні - в масив Ypozitive.
▼Прихований текст
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    double a, b, c, e, f, h;
    int k_p = 0, k_otr = 0;
    double y[31];
    bool Yn, Yp;
    double *Ynegative, *Ypozitive;
    cout << "VVedite a= ";
    cin >> a;
    cout << "VVedite b= ";
    cin >> b;
    cout << "VVedite c= ";
    cin >> c;
    cout << "VVedite e= ";
    cin >> e;
    cout << "VVedite f= ";
    cin >> f;
    h = (f - e) / 30;
    for (int j = 0; j < 30; j++)
    {
        y[j] = a * pow((e + h * j), 2) + b * (e + h * j) + c;
        if (y[j] >= 0) k_p++;
        else k_otr++;
    }
    cout << endl;
    cout << "Kol + element = " << k_p << endl;
    cout << "Kol - element = " << k_otr << endl;
    cout << endl;
    if (k_p > 0)
    {
        Yp = true;
        Ypozitive = new double[k_p];
    }
    if (Yp)
    {
        for (int i = 0; i < 30; i++)
        {
            if (y[i] >= 0)
            {
                Ypozitive[i] = y[i];
                cout << "Ypozitive[" << i + 1 << "]=" << Ypozitive[i] << endl;
            }
        }
        delete[] Ypozitive;
    }
    else
    {
        Yp = false;
        delete Ypozitive;
    }
    if (k_otr > 0)
    {
        Yn = true;
        Ynegative = new double[k_otr];
    }
    if (Yn)
    {
        for (int i = 0; i < 30; i++)
        {
            if (y[i] < 0)
            {
                Ynegative[i] = y[i];
                cout << "Ynegative[" << i + 1 << "]=" << Ynegative[i] << endl;
            }
        }
        delete[] Ynegative;
    }    
    else
    {
        Yn = false;
        delete Ynegative;
    }
    
    return 0;
}
Чи правильно складено код і блок-схема?
Як можна виправити код щоб на виході виходило такого типу:
Y - 1 2 3 -1 -2 -3
    Yneg.              Ypoz.
     -1                     1
     -2                     2
     -3                     3
     -n                     n

						Post's attachments12345.jpg 159.95 kb, 119 downloads since 2018-10-16