Matrices Programacion

You might also like

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

OPERACIONES EN MATRICES

Module Module1
Sub Main()
Dim n, my As Integer
ingresar(n)
Dim m(n, n) As Integer
leer_matriz(m, n)
mostrar_matriz(m, n)
suma_principal(m, n)
prod_arriba(m, n)
suma_cuad_abajo(m, n)
numero_mayor(m, n, My)
repite(m, n, My)
End Sub
Sub ingresar(ByRef n As Integer)
Console.Write("Ingresa el orden de la matriz: ")
n = Console.ReadLine
End Sub
Sub leer_matriz(ByRef m(,) As Integer, ByVal n As Integer)
Randomize()
Dim a, b As Integer
For a = 0 To n - 1 Step 1
For b = 0 To n - 1 Step 1
m(a, b) = Rnd() * 10 + 1
Next
Next
End Sub
Sub mostrar_matriz(ByVal m(,) As Integer, ByVal n As Integer)
Dim a As Integer
Console.WriteLine()
For a = 0 To n - 1 Step 1
For b = 0 To n - 1 Step 1
Console.SetCursorPosition((5 * b) + 4, (3 * a) + 3)
Console.Write("{0}", m(a, b))
Next
Next
Console.ReadLine()
End Sub
Sub suma_principal(ByVal m(,) As Integer, ByVal n As Integer)
Dim c, s As Integer
s = 0
For c = 0 To n - 1 Step 1
s = s + m(c, c)
Next
Console.SetCursorPosition(0, (3 * n) + 3)
Console.Write("La suma de la diagonal principal es {0}", s)
Console.ReadLine()
End Sub
Sub prod_arriba(ByVal m(,) As Integer, ByVal n As Integer)
Dim f, c, p As Integer
p = 1
For f = 0 To n - 1 Step 1
For c = 0 To n - 1 Step 1
If (c > f) Then
p = p * m(f, c)
End If
Next
Next
Console.Write("La producto es de los elementos encima de la D. Principal
es : {0}", p)
Console.ReadLine()
End Sub
Sub suma_cuad_abajo(ByVal m(,) As Integer, ByVal n As Integer)
Dim f, c, s As Integer
s = 0
For f = 0 To n - 1 Step 1
For c = 0 To n - 1 Step 1
If (f > c) Then
s = s + Math.Pow(m(f, c), 2)
End If
Next
Next
Console.Write("La suma de cuadrados de los elementos por debajo de la D.P
es: {0}", s)
Console.ReadLine()
End Sub
Sub numero_mayor(ByVal m(,) As Integer, ByVal n As Integer, ByRef my As Integer)
Dim f, c, p1, p2 As Integer
my = 0
For f = 0 To n - 1 Step 1
For c = 0 To n - 1 Step 1
If (m(f, c) > my) Then
my = m(f, c)
p1 = f
p2 = c
End If
Next
Next
Console.Write("La nmero mayor es es {0}", my)
Console.ReadLine()
End Sub
Sub repite(ByVal m(,) As Integer, ByVal n As Integer, ByVal my As Integer)
Dim f, c, r As Integer
r = 0
For f = 0 To n - 1 Step 1
For c = 0 To n - 1 Step 1
If (my = m(f, c)) Then
r = r + 1
Console.Write("Se escuendra en la posicion: ({0},{1}) ", f + 1,
c + 1)
End If
Next
Next
Console.Write("Se repite {0} veces ", r)
Console.ReadLine()
End Sub
End Module

You might also like