0% found this document useful (0 votes)
35 views3 pages

Find The Second Largest Element in An Array June 24, 2014

The document describes finding the second largest element in an array using Visual Basic. It outlines the steps to create a console application project in Visual Studio, declare variables, get input values using a for loop, and use nested for loops with a flag variable to find the second largest element. The coding section shows the Visual Basic code implementing these steps. It takes array input from the user, compares elements using nested for loops, increments a flag when an element is smaller, and prints the second largest element when the flag is 1.

Uploaded by

Amutha Arun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Find The Second Largest Element in An Array June 24, 2014

The document describes finding the second largest element in an array using Visual Basic. It outlines the steps to create a console application project in Visual Studio, declare variables, get input values using a for loop, and use nested for loops with a flag variable to find the second largest element. The coding section shows the Visual Basic code implementing these steps. It takes array input from the user, compares elements using nested for loops, increments a flag when an element is smaller, and prints the second largest element when the flag is 1.

Uploaded by

Amutha Arun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

2.

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

2. FIND THE SECOND LARGEST ELEMENT IN AN ARRAY June 24, 2014

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

2. FIND THE SECOND LARGEST ELEMENT IN AN ARRAY June 24, 2014

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

You might also like