Answer to Question #212589 in Visual Basic for Fatma th

Question #212589

Write a VB program to swap the 1st quarter elements of one dimension integer

array of size 12 with 2nd quarter elements.


1
Expert's answer
2021-07-01T13:19:27-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS