Home >>VB.Net Programs >VB.Net Program to demonstrate the Math.DivRem() method

VB.Net Program to demonstrate the Math.DivRem() method

Write a VB.Net Program to demonstrate the Math.DivRem() method

Here, using the DivRem() method of Math class, we can find the quotient and remainder and then print the quotient and remainder values on the console screen.

Program :

Below is the source code for showing the Math.DivRem() method. The program given is compiled and successfully executed.

Example


Module Module1
    Sub Main()
        Dim quotient As Integer = 0
        Dim remainder As Integer = 0
        Dim num1 As Integer = 0
        Dim num2 As Integer = 0
        Console.Write("Enter the value of num1: ")
        num1 = Integer.Parse(Console.ReadLine())
        Console.Write("Enter the value of num2: ")
        num2 = Integer.Parse(Console.ReadLine())
        quotient = Math.DivRem(num1, num2, remainder)
        Console.WriteLine("Quotient is: {0}", quotient)
        Console.WriteLine("Remainder is: {0}", remainder)
    End Sub
End Module
	
Output:
Enter the value of num1: 17
Enter the value of num2: 5
Quotient is: 3
Remainder is: 2

Explanation:

We created four variables in the above program: quotient, remainder, num1, and num2, initialized with 0 We then read the num1 and num2 values from the user after that.

Console.WriteLine("Quotient is: {0}", quotient)
Console.WriteLine("Remainder is: {0}", remainder)

The quotient and the remainder are identified in the above code using DivRem() of the Math class and then the result is printed on the console screen.


No Sidebar ads