Write a VB program to swap the 1st quarter elements of one dimension integer
array of size 12 with 2nd quarter elements.
Module Module1
Sub Main()
Dim elements(11) As Integer
For i As Integer = 0 To 11
Console.Write("Enter element {0}: ", (i + 1))
Integer.TryParse(Console.ReadLine(), elements(i))
Next
'Display array
Console.WriteLine("All elements: ")
For i As Integer = 0 To 11
Console.Write(elements(i).ToString() + " ")
Next
'swap the 1st quarter elements of one dimension integer
'array of size 12 with 2nd quarter element
Dim tempElements(2) As Integer
Dim index As Integer = 3
For i As Integer = 0 To 2
tempElements(i) = elements(i)
elements(i) = elements(index)
index += 1
Next
index = 0
For i As Integer = 3 To 5
elements(i) = tempElements(index)
index += 1
Next
'Display array
Console.WriteLine(vbNewLine + "All elements after swapping the 1st quarter elements of array ith 2nd quarter elements: ")
For i As Integer = 0 To 11
Console.Write(elements(i).ToString() + " ")
Next
Console.ReadLine()
End Sub
End Module
Comments
Leave a comment