-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExMethodes2.cs
55 lines (52 loc) · 1.43 KB
/
ExMethodes2.cs
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
using Logique;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Threading.Tasks;
namespace exercices
{
internal class ExMethodes2 : iCommand
{
public string Name => "02_ExMéthodes";
public void Execute()
{
EQ2D[] eq1 = new EQ2D[]
{
new EQ2D{A=1,B=1,C=-2 },
new EQ2D{A=1,B=1,C=1},
new EQ2D{A=4,B=1,C=-2 }
};
foreach (EQ2D eq in eq1)
{
double? x1, x2;
if (eq.Resoudre(out x1, out x2))
{
Console.WriteLine(x1 == x2 ? $"X={x1}" : $"X1={x1} X2={x2}");
}
else
{
Console.WriteLine("Impossible");
}
}
}
public struct EQ2D
{
public double A,B,C;
public bool Resoudre(out double? x1, out double? x2)
{
x1 = null;
x2 = null;
if (A == 0)
return false;
double delta = (Math.Pow(B, 2)) - (4 * A * C);
if(delta < 0)
return false;
x1 = (-B-Math.Sqrt(delta))/(2*A);
x2 = (-B + Math.Sqrt(delta)) / (2 * A);
return true;
}
}
}
}