F# program to perform Arithmetic Operations
Program
open System
let add a b = a + b
let subtract a b = a - b
let multiply a b = a * b
let divide a b = try
let mutable c = 0
c <- a / b;
Console.WriteLine("Quotient of two numbers is:\t{0}" , c); 1
with
| :? System.DivideByZeroException as ex -> Console.WriteLine(ex.Message); 0
let modulo a b = try
let mutable m = 0
m <- a % b;
Console.WriteLine("Modulus of two numbers is:\t{0}" , m); 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())
// Calling Functions
let sum = add first second;
Console.WriteLine("Sum of two numbers is:\t{0}" ,sum)
let difference = subtract first second;
Console.WriteLine("Difference of two numbers is:\t{0}" ,difference)
let product = multiply first second;
Console.WriteLine("Product of two numbers is:\t{0}" ,product)
let quotient = divide first second;
let modulus = modulo first second;
Output 1
Enter the first number: 100
Enter the second number: 10
Sum of two numbers is: 110
Difference of two numbers is: 90
Product of two numbers is: 1000
Quotient of two numbers is: 10
Modulus of two numbers is: 0
Output 2
Enter the first number: 56
Enter the second number: 0
Sum of two numbers is: 56
Difference of two numbers is: 56
Product of two numbers is: 0
Attempted to divide by zero.
Attempted to divide by zero.