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
 93
 94
 95
 96
 97
 98
 99
100
101
102
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LR1_fun_out_struct_OOP
{
class Program
{
struct mnogochlen
{
public int n;
public double[] a;
}
public double[] vvod(int n, double[] a)
{
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());
}
return a;
}
public double[] output(double[] a)
{
Console.WriteLine("\nМногочлен:");
for (int i = a.Length - 1; i >= 0; i--)
{
try
{
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;
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
return a;
}
public double obschet(double x, double[] a)
{
double y;
y = a[a.Length - 1] * x + a[a.Length - 2];
for (int i = 3; i <= a.Length; i++)
{
y = y * x + a[a.Length - i];
}
return y;
}
static void Main(string[] args)
{
mnogochlen obj = new mnogochlen();
Program obj1 = new Program();
obj.a = obj1.vvod(obj.n, obj.a);
obj1.output(obj.a);
Console.WriteLine("\n\nВведите значение x:");
double x = double.Parse(Console.ReadLine());
Console.WriteLine("\nРезультат вычисления многочлена = " + obj1.obschet(x, obj.a));
Console.ReadKey();
}
}
}