F# program to find Modulus of two numbers using Try Catch
Program
open System
Console.Write("Enter the first number:\t")
let a = Int32.Parse(Console.ReadLine())
Console.Write("Enter the second number:\t")
let b = Int32.Parse(Console.ReadLine())
let modulus = try
let modulo = a % b
Console.WriteLine("Modulus of two numbers is:\t{0}" , modulo); 1
with
| :? System.DivideByZeroException as ex -> Console.WriteLine(ex.Message); 0
Output 1
Enter the first number: 54
Enter the second number: 4
Modulus of two numbers is: 2
Output 2
Enter the first number: 1
Enter the second number: 8
Modulus of two numbers is: 1
Output 3
Enter the first number: 678
Enter the second number: 0
Attempted to divide by zero.