diff --git a/lab 5/FunctionFactory/FunctionFactory.fsproj b/lab 5/FunctionFactory/FunctionFactory.fsproj new file mode 100755 index 0000000..299cf40 --- /dev/null +++ b/lab 5/FunctionFactory/FunctionFactory.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net7.0 + + + + + + + diff --git a/lab 5/FunctionFactory/Program.fs b/lab 5/FunctionFactory/Program.fs new file mode 100755 index 0000000..bc730a5 --- /dev/null +++ b/lab 5/FunctionFactory/Program.fs @@ -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 + +[] +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