using System using System Collections Generic using System Linq using

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LR1_1_OOP
{
class Program
{
public struct mnogochlen
{
int n;
double[] a;
public void vvod()
{
Console.WriteLine("\nВведите порядок многочлена");
n = int.Parse(Console.ReadLine());
a = new double[n + 1];
Console.WriteLine("\n");
for (int i = n; i >= 0; i--)
{
Console.WriteLine("Введите " + i + "-ый коефициент");
a[i] = double.Parse(Console.ReadLine());
}
}
public void output()
{
Console.WriteLine("\nМногочлен:");
for (int i = n; i >= 0; i--)
{
if (a[i] != 0)
{
switch (i)
{
case 1:
if (a[i]<0)
{
Console.Write(a[i]+"x");
}
else
{
Console.Write("+"+ a[i] + "x");
}
break;
case 0:
if (a[i] < 0)
{
Console.Write(a[i]);
}
else
{
Console.Write("+" + a[i]);
}
break;
default:
if (a[i] > 0)
{
Console.Write("+" + a[i] + "x^" + i);
}
else
{
Console.Write(a[i] + "x^" + i);
}
break;
}
}
}
}
public double obschet(double x)
{
double y;
y = a[n] * x + a[n - 1];
for (int i = 2; i <= n; i++)
{
y = y * x + a[n - i];
}
return y;
}
}
static void Main(string[] args)
{
mnogochlen obj = new mnogochlen();
obj.vvod();
obj.output();
Console.WriteLine("\n\nВведите значение x:");
double x = double.Parse(Console.ReadLine());
Console.WriteLine("\nРезультат вычисления многочлена = " + obj.obschet(x));
Console.ReadKey();
}
}
}