You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
998 B
34 lines
998 B
// 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
|