using System;
using System.Diagnostics;
using System.Drawing;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Write("a="); double a = Convert.ToDouble(Console.ReadLine());
Console.Write("b="); double b = Convert.ToDouble(Console.ReadLine());
Console.Write("c="); double c = Convert.ToDouble(Console.ReadLine());
Console.Write("d="); double d = Convert.ToDouble(Console.ReadLine());
double range = 20;
double x = -range, dx = 0.000002, y1, y2, p = 0, dp, minY=Double.MaxValue, maxY=Double.MinValue;
y1 = a * x * x * x + b * x * x + c * x + d;
y2 = y1;
Stopwatch sw = new Stopwatch();
sw.Start();
while (x < range)
{
y1 = a * x * x * x + b * x * x + c * x + d;
if (y1 * y2 < 0)
Console.WriteLine($"x={x}");
y2 = y1;
if (y1 > maxY)
maxY = y1;
if (y1 < minY)
minY = y1;
dp = (y1 + y2) * dx / 2;
if (dp < 0)
dp = -dp;
p += dp;
x += dx;
}
sw.Stop();
Console.WriteLine($"pole={p} " + sw.Elapsed);
Bitmap bmp = new Bitmap(1000, 750);
Graphics gr = Graphics.FromImage(bmp);
Pen pen = new Pen(Color.Black);
Pen pr = new Pen(Color.Red);
gr.FillRectangle(new SolidBrush(Color.White), 0, 0, bmp.Width, bmp.Height);
gr.DrawLine(pen, 0, bmp.Height / 2, bmp.Width, bmp.Height / 2);
gr.DrawString($"{range}", new Font(FontFamily.GenericSansSerif, 18), new SolidBrush(Color.Red),
new Point(0, bmp.Height / 2));
// gr.DrawLine(pen, 0, bmp.Height / 2, bmp.Width, bmp.Height / 2);
double scaleY = bmp.Height / (maxY - minY);
double scaleX = bmp.Width / (2 * range);
x = -range;
y1 = a * x * x * x + b * x * x + c * x + d;
y2 = y1;
dx = 2*range / bmp.Width;
while (x < range)
{
y1 = a * x * x * x + b * x * x + c * x + d;
gr.DrawLine(pr, (int) (bmp.Width / 2 + (x-dx) * scaleX), (int) (bmp.Height / 2 - y2 * scaleY),
(int) (bmp.Width / 2 + x * scaleX), (int) (bmp.Height / 2 - y1 * scaleY));
y2 = y1;
x += dx;
}
bmp.Save("bmp.png");
Console.ReadLine();
}
}
}