Logo 
Search:

VB.Net Forum

Ask Question   UnAnswered
Home » Forum » VB.Net       RSS Feeds

array

  Asked By: Priya    Date: Jan 03    Category: VB.Net    Views: 5635
  

source code to find first three smallest values in an array....
for eg,
a[]={20,18,2,10,5,90}
answer should be 2,5,10........
can anyone give me a suggestion.....

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Shruti Sharma     Answered On: Jan 03

Hi Priya,

Create one vb.net web application and replace page load method with following


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim MyArrList As ArrayList = New ArrayList()

'Initialize Array
MyArrList.Add(20)
MyArrList.Add(18)
MyArrList.Add(2)
MyArrList.Add(10)
MyArrList.Add(5)
MyArrList.Add(90)

'Sort elements in array to get smallest value
MyArrList.Sort()

'For displaying result
Dim sbResult As StringBuilder = New StringBuilder()
For I As Integer = 1 To 3 Step 1
If I = 3 Then
sbResult.Append(MyArrList(I - 1).ToString())
Else
sbResult.Append(MyArrList(I - 1).ToString() + ", ")
End If
Next

'Displaying result on browser
Response.Write("Smallest Three values are: " + sbResult.ToString())
End Sub

 
Didn't find what you were looking for? Find more on array Or get search suggestion and latest updates.
This post is locked for further answers.




Tagged: