Home »
VB.Net »
VB.Net Programs
VB.Net program to find the largest element from the array of integers
Here, we are going to learn how to find the largest element from the array of integers in VB.Net?
Submitted by Nidhi, on December 07, 2020 [Last updated : March 06, 2023]
Largest element in an integer array
Here, we will create an array of integers and then read elements from the user after that find the largest element from the array and print the biggest element on the console screen.
Program/Source Code:
The source code to find the largest element from the array of integers is given below. The given program is compiled and executed successfully.
VB.Net code to find the largest element in an integer array
'VB.Net program to find the largest element
'from the array of integers.
Module Module1
Sub Main()
Dim arr As Integer() = New Integer(5) {}
Dim large As Integer = 0
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())
If (large < arr(i)) Then
large = arr(i)
End If
Next
Console.WriteLine("Largest element in array is: {0}", large)
End Sub
End Module
Output:
Enter array elements:
Element[0]: 12
Element[1]: 14
Element[2]: 23
Element[3]: 16
Element[4]: 13
Largest element in array is: 23
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains a function Main().
Dim arr As Integer() = New Integer(5) {}
Dim large As Integer = 0
In the Main() we created an array arr of five elements and an integer variable large, which is initialized with 0.
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())
If (large < arr(i)) Then
large = arr(i)
End If
Next
Console.WriteLine("Largest element in array is: {0}", large)
In the above code, we read the elements of an array from the user and find the largest element by comparing each element and update the value of the variable, if we found an element larger than variable large then we found the largest element in variable large and then print the largest element on the console screen.
VB.Net Array Programs »