﻿ VB.NET exercises and solutions: arithmetic operators

# 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.

Solution:

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)

Console.ReadLine()

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 .

Solution:

Module Module1

Sub Main()

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

End Sub

End Module

### Comments ShriWill u tell the purpose of gIvinghoe this {0} in write line statement..in arithmetic Operators program2018-01-06 Asadit helps me alot thanks!!! 2016-11-13 Ahsannice site.....2016-09-23 priyaNice example. This s very helpful to me.thanks a lot.....2014-09-10
﻿

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.