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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace огыеагт
{
class Program
{
static void Main(string[] args)
{
ParameterExpression value = Expression.Parameter(typeof(double), "value");
ParameterExpression value2 = Expression.Parameter(typeof(double), "value2");
ParameterExpression result = Expression.Parameter(typeof(double), "result");
ParameterExpression mainResult = Expression.Variable(typeof(double), "mainResult");
LabelTarget label = Expression.Label(typeof(double));
BlockExpression block = Expression.Block(
new[] { result,mainResult },
Expression.Assign(mainResult, Expression.Constant(0.0)),
Expression.Assign(result, Expression.Constant(1.0)),
Expression.Loop(
Expression.IfThenElse(
Expression.GreaterThan(value2, Expression.Constant(0.0)),
Expression.AddAssign(mainResult,
Expression.MultiplyAssign(result,
Expression.Divide(value,
Expression.PostDecrementAssign(value2)
)
)
),
Expression.Break(label, mainResult)
),
label
)
);
for (double j = 0.1; j <= 1.01; j += 0.05)
{
int i = 0;
double sum = 1, res = 0;
while (sum > 0.0004)
{
sum = Expression.Lambda<Func<double, double, double>>(block, value, value2).Compile()(j, 2 * i + 1);
i++;
res += sum;
}
double y = 0;
y = (Math.Pow(Math.E, j) - Math.Pow(Math.E, -j)) / 2;
Console.WriteLine("{0:f2} {1:f4} {2:f4}", j, res, y);
}
Console.ReadKey();
}
}
}