0% found this document useful (0 votes)
17 views

Array Intro, Linear, Bubble

This program demonstrates several array operations including: 1) Inputting values into an array from the user 2) Outputting the contents of the array 3) Calculating the average, highest, and lowest values in the array 4) Sorting the array using bubble sort 5) Searching for a value in the array using linear search

Uploaded by

Chingez Khan
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Array Intro, Linear, Bubble

This program demonstrates several array operations including: 1) Inputting values into an array from the user 2) Outputting the contents of the array 3) Calculating the average, highest, and lowest values in the array 4) Sorting the array using bubble sort 5) Searching for a value in the array using linear search

Uploaded by

Chingez Khan
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Module Module1

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

Loop Until found Or count > size


If found Then
Console.WriteLine("the index is " & count)
Else
Console.WriteLine("ni milaaaaaaa :)")
End If
Console.ReadKey()
End Sub

End Module

You might also like