Find The Second Largest Element in An Array June 24, 2014
Find The Second Largest Element in An Array June 24, 2014
Aim:
~~~
To write a program the second largest element in an using .net.
Procedure:
~~~~~~~~
Step1: Start the program in the Microsoft Visual Studio 2010.
Step2: File->new->project Select the project type as visual basic and select
the visual studio installed template as console application.
Step3: Choose a Name, Location and Solution name.
Step4: Declare the variable.
Step5: Get the input values by using for loop.
Step6: To find the second largest element in a given group of element by using for
loop with flag values.
Step7:If the value is equal to one then print the corresponding element .
Step8: End of the program.
12PA01
Page 4
Coding:
~~~~~~
Module Module1
Sub Main()
Dim a(10) As Integer
Dim n, i, j, f As Integer
f=0
Console.WriteLine("Array Largest Second Element")
Console.WriteLine("*************************")
Console.WriteLine("Input")
Console.WriteLine("~~~~")
Console.WriteLine("Enter the number of element :")
n = Console.ReadLine()
Console.WriteLine("Enter the value :")
For i = 1 To n
a(i) = Console.ReadLine()
Next i
Console.WriteLine("Output")
Console.WriteLine("~~~~~")
For i = 1 To n
For j = 1 To n
If (a(i) < a(j)) Then
f=f+1
End If
Next j
If f = 1 Then
Console.WriteLine("The Result is :")
Console.WriteLine(a(i))
End If
f=0
Next i
Console.ReadKey()
End Sub
End Module
12PA01
Page 5
Output
~~~~~~
Array Largest Second Element
*************************
Input
~~~~
Enter the number of element :
5
Enter the value :
10
15
24
2
30
Output
~~~~~
The Result is :
24
Result:
*****
Thus the second largest element in an array program was successfully performed.
12PA01
Page 6