using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication_Lab3_1
{
class Program
{
static double a, b, c, d;
static void Main(string[] args)
{
double h = 0.0005, x0 = -5, xh, xn = 5, x;
double[] A = new double[10];
int i = 0;
string st;
FileStream s = new FileStream("a.txt", FileMode.Open);
StreamReader Re = new StreamReader(s);
//Считывание из файла "a.txt" постоянных a,b,c,d
st = Re.ReadLine();
a = Convert.ToDouble(st);
Console.WriteLine("a= {0:f2}", a);
st = Re.ReadLine();
b = Convert.ToDouble(st);
Console.WriteLine("b= {0:f2}", b);
st = Re.ReadLine();
c = Convert.ToDouble(st);
Console.WriteLine("c= {0:f2}", c);
st = Re.ReadLine();
d = Convert.ToDouble(st);
Console.WriteLine("d= {0:f2}", d);
Re.Close();
s.Close();
x = x0;
A[0] = x0;
Console.WriteLine();
Console.WriteLine("Корни уравнения ax^3+bx^2+cx+d=0");
while (x <= xn)
{
xh = x + h;
if (f(x) * f(xh) <= 0)
{
i++;
A[i] = x + h / 2;
Console.WriteLine("i={0} x={1:f3}", i, A[i]);
}
x += h;
}
if (i == 0)
Console.WriteLine("Уравнение ax^3+bx^2+cx+d=0 в заданном интервале x корней не имеет");
A[i + 1] = xn;
Console.WriteLine();
FileStream u = new FileStream("rez1.txt", FileMode.Create);
StreamWriter Wr = new StreamWriter(u);
Console.WriteLine("Результаты решения неравенства ax^3+bx^2+cx+d>0");
for (int j = 0; j <= i; j++)
{
if (f(A[j] + h) > 0)
{
Console.WriteLine("Неравенство верно на интервале [{0:f3}; {1:f3}]", A[j], A[j + 1]);
Wr.WriteLine("Неравенство верно на интервале [{0:f3}; {1:f3}]", A[j], A[j + 1]);
}
else
{
Console.WriteLine("Неравенство неверно на интервале [{0:f3}; {1:f3}]", A[j], A[j + 1]);
Wr.WriteLine("Неравенство неверно на интервале [{0:f3}; {1:f3}]", A[j], A[j + 1]);
}
}
Console.ReadLine();
Wr.Close();
u.Close();
}
static double f(double x)
{
return a * x * x * x + b * x * x + c * x + d;
}
}
}






