using System using System IO using System Collections Generic using Sy

 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
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Линейная_интерполяция
{
class Program
{
static double interrot(double x0, double y0, double x1, double y1, double x)
{
return y1 + (y0 - y1) / (x0 - x1) * (x - x1);
}
static double K(double x0, double y0, double x1, double y1, double x)
{
return (y1 - y0) / (x1 - x0);
}
static double B(double x0, double y0, double x1, double y1, double x)
{
return y0 - x0 * (y1 - y0) / (x1 - x0);
}
static void sort(double[] a, double[] b)
{
for (int i = 0; i < a.Length - 1; ++i)
{
for (int j = i + 1; j < a.Length; ++j)
{
if (a[j] < a[i])
{
double temp = a[j];
a[j] = a[i];
a[i] = temp;
temp = b[j];
b[j] = b[i];
b[i] = temp;
}
}
}
}
static void Main(string[] args)
{
double[] a = new double[] { 5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80 };
double[] b = new double[] { 37.5, 43, 47, 50, 52.6, 55.3, 60, 64.1, 68, 72, 76 };
sort(a, b);
Console.WriteLine("Значения Х и Y:");
Console.Write("x: ");
for (int i = 0; i < a.Length; i++)
{
Console.Write("{0} ", a[i]);
}
Console.WriteLine();
Console.Write("y: ");
for (int i = 0; i < b.Length; i++)
{
Console.Write("{0} ", b[i]);
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Введите значение Х");
Console.WriteLine();
Vvod:
string s = Console.ReadLine();
double x = double.Parse(s);
if (x < a[0] || x > a[a.Length - 1])
{
Console.WriteLine("Х вышел за пределы");
goto Vvod;
}
else
{
int k = 0;
for (int i = 0; i < a.Length - 1; i++)
{
if ((a[i] - x) * (a[i + 1] - x) <= 0)
{
k = i;
}
}
double fx = interrot(a[k], b[k], a[k + 1], b[k + 1], x), k1 = K(a[k], b[k], a[k + 1], b[k + 1], x), b1 = B(a[k], b[k], a[k + 1], b[k + 1], x);
Console.WriteLine("F({0}) = ({1:f4})*x + ({2:f4}) = {3:f4}", x, k1, b1, fx);
goto Vvod;
}
}
}
}