F# program to find Modulus of two numbers using Functions
Program
open System
let modulus a b = try
let mutable c = 0
c <- a % b;
Console.WriteLine("Modulus of two numbers is:\t{0}" , c); 1
with
| :? System.DivideByZeroException as ex -> Console.WriteLine(ex.Message); 0
Console.Write("Enter the first number:\t")
let first = Int32.Parse(Console.ReadLine())
Console.Write("Enter the second number:\t")
let second = Int32.Parse(Console.ReadLine())
// Function modulus is called
let result = modulus first second
Output 1
Enter the first number: 456
Enter the second number: 5
Modulus of two numbers is: 1
Output 2
Enter the first number: 4
Enter the second number: 789
Modulus of two numbers is: 4
Output 3
Enter the first number: 333
Enter the second number: 0
Attempted to divide by zero.