Array Intro, Linear, Bubble
Array Intro, Linear, Bubble
Sub Main()
'set up an array
'multiple elements
'output the contents of that array
'find the average of the numbers entered
'highest
'lowest
'bubble sort
'find an item from the array using linear search
Dim num(4) As Integer
Dim total, highest, lowest, count As Integer
Dim avg As Double
total = 0
highest = 0
lowest = 9999
For count = 0 To 4
Console.WriteLine("please enter numbers")
num(count) = Console.ReadLine
Next
For count = 0 To 4
Console.WriteLine(num(count))
Next
For count = 0 To 4
total = total + num(count)
'you always have to use loop! for is the best option! you always
'have to manipulate the indexes to manipulate array
If num(count) > highest Then highest = num(count)
If num(count) < lowest Then lowest = num(count)
Next
avg = total / 5
Console.WriteLine("the average is " & avg & " highest is " & highest & "
lowest is " & lowest)
Dim top, temp As Integer
Dim swap As Boolean
top = 4
Do
swap = False
For count = 0 To top - 1
If num(count) > num(count + 1) Then
temp = num(count)
num(count) = num(count + 1)
num(count + 1) = temp
swap = True
End If
Next
top = top - 1
Loop Until Not swap Or top = 0
For count = 0 To 4
Console.WriteLine(num(count))
Next
Dim size As Integer
Dim found As Boolean
size = 4
count = 0
found = False
Console.WriteLine("btao kya dhoond rahay ho? :)")
Dim dhoondo As Integer = Console.ReadLine
Do
If dhoondo = num(count) Then
found = True
Else
count = count + 1
End If
End Module