Home »
VB.Net »
VB.Net Programs
VB.Net program to find the EVEN numbers from the array of integers
Here, we are going to learn how to find the EVEN numbers from the array of integers in VB.Net?
Submitted by Nidhi, on December 07, 2020 [Last updated : March 06, 2023]
Print EVEN numbers in an integer array
Here, we will create an array of integers and then read elements from the user, after that we will find the EVEN numbers from the array and print them on the console screen.
Program/Source Code:
The source code to find the EVEN numbers from the array of integers is given below. The given program is compiled and executed successfully.
VB.Net code to print the EVEN numbers in an integer array
'VB.Net program to find the EVEN numbers
'from the array of integers.
Module Module1
Sub Main()
Dim arr As Integer() = New Integer(5) {}
Console.WriteLine("Enter array elements: ")
For i As Integer = 0 To 4 Step 1
Console.Write("Element[{0}]: ", i)
arr(i) = Integer.Parse(Console.ReadLine())
Next
Console.WriteLine("EVEN Numbers are: ")
For i As Integer = 0 To 4 Step 1
If (arr(i) Mod 2) = 0 Then
Console.Write("{0} ", arr(i))
End If
Next
Console.WriteLine()
End Sub
End Module
Output
Enter array elements:
Element[0]: 12
Element[1]: 13
Element[2]: 14
Element[3]: 15
Element[4]: 16
EVEN Numbers are:
12 14 16
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains a function Main().
In the Main() we created an array arr of five elements.
Console.WriteLine("Enter array elements: ")
For i As Integer = 0 To 4 Step 1
Console.Write("Element[{0}]: ", i)
arr(i) = Integer.Parse(Console.ReadLine())
Next
In the above code, we read the elements of the array from the user.
Console.WriteLine("EVEN Numbers are: ")
For i As Integer = 0 To 4 Step 1
If (arr(i) Mod 2) = 0 Then
Console.Write("{0} ", arr(i))
End If
Next
Console.WriteLine()
In the above code, we found the EVEN numbers from the array and then print them on the console screen.
VB.Net Array Programs »