none
CUADRADO MAGICO VISUAL BASIC 2008 RRS feed

  • Pregunta

  • Public Class Form1

        Public Sub CUADRADO_MAGICO(ByRef MAT As Array, ByRef N As Integer)
            Dim I, J, NUM As Integer
            I = 0
            J = N Mod 2
            NUM = 1
            MAT(0, N \ 2) = NUM
            NUM = 2
            While NUM <= N * N
               
                If NUM - 1 Mod N <> 0 Then
                    I = I - 1
                    J = J + 1
                    If I < 0 Then
                        I = N - 1
                        MAT(I, J) = NUM
                        NUM = NUM + 1
                    Else
                        If J > N - 1 Then
                            J = 0
                            MAT(I, J) = NUM
                            NUM = NUM + 1
                        Else
                            MAT(I, J) = NUM
                            NUM = NUM + 1

                        End If
                    End If
                End If
                If NUM - 1 Mod N = 0 Then
                    I = I + 1
                    If I > N - 1 Then
                        I = 0
                        MAT(I, J) = NUM
                        NUM = NUM + 1
                    Else
                        MAT(I, J) = NUM
                        NUM = NUM + 1
                    End If
                End If
               
            End While
           
            For I = 0 To N - 1
                J = 0
                For J = 0 To N - 1
                    MsgBox(MAT(I, J))
                Next

            Next
           
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim N As Integer


            N = InputBox("INGRESE LAS DIMENSIONES DEL CUADRADO, EL NUMERO DEBE SER IMPAR. EJEMPLO: 5 PARA UN CUDRADO DE 5X5")
            Dim MAT(,) As Integer
            ReDim MAT(0 To N - 1, 0 To N - 1)
            CUADRADO_MAGICO(MAT, N)
           

        End Sub
    End Class


    UN EJEMPLO DE COMO DEBERIA QUEDAR ES:

    8-1-6

    3-5-7

    4-9-2

    PERO ME TIRA "0" NADA MAS NO SE PORQUE

    GRACIAS

    sábado, 12 de junio de 2010 3:46