(lab 5) feat: add Quadratic Equation solver

main
Artem-Darius Weber 3 weeks ago
parent 592fddf73d
commit ac5ae13f36

@ -0,0 +1,36 @@
// For more information see https://aka.ms/fsharp-console-apps
printfn "Hello from F#"
// ax² + bx + c = 0
let solveQuadratic (a: float) (b: float) (c: float) =
let discriminant = b * b - 4.0 * a * c
match discriminant with
| d when d > 0.0 ->
let x1 = (-b + sqrt(d)) / (2.0 * a)
let x2 = (-b - sqrt(d)) / (2.0 * a)
printfn "Уравнение имеет два различных корня:"
printfn "x₁ = %.4f" x1
printfn "x₂ = %.4f" x2
| d when d = 0.0 ->
let x = -b / (2.0 * a)
printfn "Уравнение имеет один корень (кратности 2):"
printfn "x = %.4f" x
| _ ->
printfn "Уравнение не имеет действительных корней"
[<EntryPoint>]
let main argv =
printfn "Решение квадратного уравнения ax² + bx + c = 0"
printfn "Введите коэффициенты a, b, c:"
let a = System.Console.ReadLine() |> float
let b = System.Console.ReadLine() |> float
let c = System.Console.ReadLine() |> float
if a = 0.0 then
printfn "Ошибка: коэффициент a не может быть равен нулю"
else
solveQuadratic a b c
0

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
</Project>
Loading…
Cancel
Save