﻿ 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:")
Console.Write("Enter value b:")
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 .

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)

End Sub

End Module