Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Tawanda Mafurirano Bubble sort Friday 30 April 2021

Screenshot
The Code
Module Module1
Sub sorting(ByVal x() As Integer, ByVal y As Integer)
Dim i, a, t As Integer
For i = 0 To y - 1
For a = i + 1 To y - 1
If x(i) > x(a) Then
t = x(i)
x(i) = x(a)
x(a) = t
End If
Next
Next
End Sub
Sub Main()
Console.WriteLine("Bubble Sorting By Tawanda Mafuriano")
Console.WriteLine()
Dim num, i As Integer
Console.Write("Enter Number of Elements: ")
num = CInt(Console.ReadLine)
Dim arr(num) As Integer
Console.WriteLine()
For i = 0 To num - 1
Console.Write("Enter Element(" & (i + 1) & "): ")
arr(i) = CInt(Console.ReadLine)
Next

Console.WriteLine()
sorting(arr, num)
Console.WriteLine("Sorted Elements")
Console.WriteLine()
For i = 0 To num - 1
Console.WriteLine("Element in (" & i & "): " & arr(i))
Next
Console.ReadLine()
End Sub

End Module

You might also like