January 24, 2014

Replacing two strings in a random matrix.

The program Swaps the lines Str1 and Str2 in a random matrix.
Programming language: Visual Basic.

Code:
Module Module1

    Sub Main()
        Dim s1, s2, temp, a(4, 4) As Integer

        For i = 0 To 4
            For j = 0 To 4
                a(i, j) = Rnd() * 9
                Console.Write(a(i, j) & "  ")
            Next
            Console.WriteLine()
            Console.WriteLine()
        Next
        Console.Write("Please, enter the Str1 here: ")
        s1 = Console.ReadLine()
        Console.Write("Please, enter the Str2 here: ")
        s2 = Console.ReadLine()

        Console.WriteLine()
        For i = 0 To 4
            temp = a(s1, i)
            a(s1, i) = a(s2, i)
            a(s2, i) = temp

        Next
        For i = 0 To 4
            For j = 0 To 4

                Console.Write(a(i, j) & "  ")
            Next
            Console.WriteLine()
            Console.WriteLine()
        Next

        Console.ReadKey()
    End Sub

End Module

No comments:

Post a Comment