(lab 5) feat: add Function Factory example

main
Artem-Darius Weber 3 weeks ago
parent 3ee1fb7479
commit d3af94170c

@ -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>

@ -0,0 +1,33 @@
// For more information see https://aka.ms/fsharp-console-apps
printfn "Hello from F#"
let rec sumDigits n =
match n with
| n when n < 10 -> n
| n -> (n % 10) + sumDigits (n / 10)
let rec factorial n =
match n with
| 0 | 1 -> 1
| n -> n * factorial (n - 1)
let createFunction (isSum: bool) =
match isSum with
| true -> sumDigits
| false -> factorial
[<EntryPoint>]
let main argv =
System.Console.WriteLine("Введите логическое значение (true/false):")
let isSum = System.Console.ReadLine() |> System.Boolean.Parse
System.Console.WriteLine("Введите число:")
let number = System.Console.ReadLine() |> int
let result = (createFunction isSum) number
match isSum with
| true -> System.Console.WriteLine($"Сумма цифр числа {number} равна {result}")
| false -> System.Console.WriteLine($"Факториал числа {number} равен {result}")
0
Loading…
Cancel
Save