VB.NET exercises and solutions: arithmetic operators

VB.NET arithmetic operators

Exercise 1: Write VB.NET program to allow the user to input two integer values and then the program print the results of adding, subtracting, multiplying, and dividing among the two values.

See the example below:

Enter value a:30

Enter value b:10

The result of adding is 40.

The result of subtracting is 20;

The result of multiplying is 300.

The result of dividing is 3.


Module Module1

Sub Main()

Dim a As Integer
Dim b As Integer
Console.Write("Enter value a:")
a = Integer.Parse(Console.ReadLine())
Console.Write("Enter value b:")
b = Integer.Parse(Console.ReadLine())
Console.WriteLine("The result of adding is {0}.", a + b)
Console.WriteLine("The result of subtracting is {0}.", a - b)
Console.WriteLine("The result of multiplying is {0}.", a * b)
Console.WriteLine("The result of dividing is {0}.", a / b)


End Sub

End Module

Exercise 2: Write VB.NET program to generate a random number between 1 to 6.

To generate a random number, you can use the Random class .


Module Module1

Sub Main()

Dim rdn As Integer
Dim rdnObject = New Random()
rdn = 1 + rdnObject.Next Mod 6
Console.WriteLine("The Result:{0}", rdn)

End Sub

End Module


Shri comment


Will u tell the purpose of gIvinghoe this {0} in write line statement..in arithmetic Operators program

Asad comment


it helps me alot thanks!!!

Ahsan comment


nice site.....

priya comment


Nice example. This s very helpful to me.thanks a lot.....


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.