Programacion Matrices y Vectores
Programacion Matrices y Vectores
matrices
2016
CDIGO Y NOTAS:
Module Module1
Sub ingresar(ByRef n As Integer)
Console.Write("Ingresar el nmero de alumnos: ")
2016
Arequipa Per
n = Console.ReadLine()
Console.WriteLine()
End Sub
Sub leer_notas(ByRef cod() As Integer, ByRef nota() As Single, ByVal n As Integer)
Dim x As Integer
For x = 0 To n - 1
Console.ForegroundColor = ConsoleColor.Magenta
Console.Write("cod({0}): ", x)
cod(x) = Console.ReadLine()
Console.Write("nota({0}): ", x)
nota(x) = Console.ReadLine()
Console.WriteLine(" ")
Next
End Sub
Sub Mostrar_nota(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Console.Clear()
Dim x As Integer
For x = 0 To n - 1
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine("Cod({0})= {1}", x, cod(x))
Console.WriteLine("Nota({0})= {1}", x, nota(x))
Console.WriteLine(" ")
Next
Console.WriteLine(" ")
End Sub
Sub Busqueda(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Dim ind As Integer = 0
Dim codigo As Integer
Console.ForegroundColor = ConsoleColor.Cyan
Console.Write("Ingresar cdigo: ")
codigo = Console.ReadLine()
For ind = 0 To n - 1
If codigo <> cod(ind) Then
Else
Console.ForegroundColor = ConsoleColor.Yellow
Console.Write(" Codigo = {0}", codigo)
Console.Write(" Nota = {0} ", nota(ind))
Console.WriteLine(" ")
End If
Next
End Sub
Sub nota_mayor(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Dim ind As Integer = 0
Dim mayornota As Integer = 0
Dim posicion As Integer
For ind = 0 To n - 1
If nota(ind) > mayornota Then
mayornota = nota(ind)
posicion = ind
End If
Next
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine(" La Mayor Nota es: {0} y su cdigo es: {1}", mayornota,
cod(posicion))
Grupo: APPLE
Console.WriteLine(" ")
End Sub
Sub nota_menor(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Dim ind As Integer = 0
Dim menornota As Integer = 0
Dim posicion As Integer
For ind = 0 To n - 1
If nota(ind) < menornota Then
menornota = nota(ind)
posicion = ind
End If
Next
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine(" La Menor Nota es: {0} y su cdigo es: {1}", menornota,
cod(posicion))
Console.WriteLine(" ")
End Sub
Sub adp(ByRef nota() As Single, ByRef n As Integer)
Dim ind As Integer = 0
Dim AP As Integer = 0
Dim DAP As Integer = 0
For ind = 0 To n - 1
If nota(ind) > 10.5 Then
AP = AP + 1
Else
DAP = DAP + 1
End If
Next
Console.ForegroundColor = ConsoleColor.Yellow
Console.WriteLine(" El nmero de aprobados es: {0}", AP)
Console.WriteLine(" El nmero de desaprobados es: {0}", DAP)
Console.WriteLine(" ")
End Sub
Sub frecuencia(ByRef nota() As Single, ByRef frec() As Integer, ByRef n As Integer)
Dim i, j, c As Integer
For i = 0 To n - 1
c=0
For j = 0 To n - 1
If (nota(i) = nota(j)) Then
c=c+1
End If
frec(i) = c
Next
Console.WriteLine("Frecuencia[NOTA {0}]={1}", nota(i), c)
Console.WriteLine(" ")
Next
End Sub
Sub moda(ByRef nota() As Single, ByRef frec() As Integer, ByRef n As Integer)
Dim m As Integer = 0
Dim mayorfrecuencia As Integer = 0
Dim pos As Integer
For m = 0 To n - 1
If (frec(m) > mayorfrecuencia) Then
mayorfrecuencia = frec(m)
Grupo: APPLE
pos = m
End If
Next
Console.WriteLine("La nota que ms repite es: {0}", nota(pos))
End Sub
Sub ranking(ByRef cod() As Integer, ByRef nota() As Single, ByRef n As Integer)
Dim I, J, TE, T As Integer
For I = 0 To n - 2
For J = I + 1 To n - 1
If nota(I) < nota(J) Then
T = nota(I)
nota(I) = nota(J)
nota(J) = T
TE = cod(I)
cod(I) = cod(J)
cod(J) = TE
End If
Next
Next
Console.ForegroundColor = ConsoleColor.Magenta
Console.SetCursorPosition(1, 14)
Console.WriteLine("RANKING DE NOTAS")
J = 20
For I = 0 To n - 1
Console.SetCursorPosition(1, I + J - 4)
Console.WriteLine("Codigo: {0}", cod(I))
Console.SetCursorPosition(12, I + J - 4)
Console.WriteLine("Nota: {0}", nota(I))
J=J+1
Next
End Sub
Sub MENU(ByRef cod() As Integer, ByRef nota() As Single, ByRef frec() As Integer,
ByRef n As Integer)
Dim OPC As Integer
While (OPC <> 9)
Console.Clear()
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("BASE DE DATOS")
Console.WriteLine("")
Console.WriteLine("")
Console.WriteLine("1. CODIGOS Y NOTAS
")
Console.WriteLine("2. BUSCAR POR CODIGO
")
Console.WriteLine("3. RANKING DE NOTAS
")
Console.WriteLine("4. FRECUENCIA DE NOTAS
")
Console.WriteLine("5. MODA DE NOTAS
")
Grupo: APPLE
")
End Module
NMEROS ALEATORIOS,
INTERPOLACIN:
INTEGRACIN E
Grupo: APPLE
Module Module1
Sub Mostrar_vector(ByVal V() As Integer)
Randomize()
Dim x, y, num As Integer
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine("NUMEROS ALEATORIOS SIN
REPETICION")
Console.WriteLine(" ")
For x = 0 To 10
num = Rnd() * 9 + 1
If x > 0 Then
For y = 0 To 10
If num = V(y) Then
num = Rnd() * 9 + 1
y = -1
End If
Next
End If
V(x) = num
Console.WriteLine("V({0})= {1}", x, V(x))
Next
End Sub
Sub Leer_vector(ByRef V() As Integer, ByVal n As Integer)
Randomize()
Dim x As Integer
For x = 0 To n
V(x) = Rnd() * 10 + 1
Next
End Sub
Sub mostrar_vector(ByVal v() As Integer, ByVal n As Integer)
Dim x As Integer
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
For x = 0 To n - 1
Console.WriteLine("v({0})= {1}", x, v(x))
Next
End Sub
Sub Integral(ByVal V() As Integer, ByVal P() As Integer, ByVal n
As Integer)
Dim A As Single
Dim x As Integer
Dim I As Single = 0
For x = 0 To n - 1
A = ((P(x) + P(x + 1)) * (V(x + 1) - V(x))) / 2
I=I+A
Next
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("La integral es {0}", I)
Console.WriteLine(" ")
Console.ReadLine()
Grupo: APPLE
End Sub
Sub interpolacion(ByVal v() As Integer, ByVal Z() As Integer, ByVal n As Integer)
Dim ind As Integer = 0
Dim xn, yn, i As Single
Console.Write("Ingrese el valor de XN: ")
xn = Console.ReadLine
For i = 0 To n
If xn > v(ind) Then
ind = ind + 1
Else
yn = ((Z(ind) - Z(ind - 1)) * (xn - v(ind - 1))) / (v(ind) - v(ind - 1)) + Z(ind - 1)
End If
Next
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Cyan
Console.WriteLine("EL VALOR DE YN ES DE: {0}", yn)
Console.WriteLine(" ")
Console.ReadLine()
End Sub
Sub menu()
Dim op As Integer
Dim v(10) As Integer
Do
Console.Clear()
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("MENU DE APLICACION DE VECTORES")
Console.WriteLine(" ")
Console.WriteLine("1.NUMEROS ALEATORIOS SIN REPETICION")
Console.WriteLine("2.INTERPOLACION LINEAL")
Console.WriteLine("3.INTEGRALES")
Console.WriteLine("4.SALIR")
Console.Write("Escoger Opcin: ")
op = Console.ReadLine
Console.WriteLine(" ")
Select Case (op)
Case 1
Mostrar_vector(v)
Case 2
Dim n As Integer = 5
Dim Z(n) As Integer
Dim B(n) As Integer
Leer_vector(B, n)
Mostrar_vector(B, n)
Leer_vector(Z, n)
Mostrar_vector(Z, n)
interpolacion(B, Z, n)
Case 3
Dim n As Integer = 10
Dim s(n) As Integer
Dim P(n) As Integer
Leer_vector(P, n)
Mostrar_vector(P, n)
Leer_vector(s, n)
Mostrar_vector(s, n)
Integral(P, s, n)
Grupo: APPLE
Case 4
End
End Select
Loop While (op < 5)
End Sub
Sub Main()
Dim V(10) As Integer
menu()
Console.ReadLine()
End Sub
End Module
MTODOS DE ORDENAMIENTO:
Module Module1
Function menu()
Dim op As Integer
Console.SetCursorPosition(10, 0)
Console.WriteLine("ORDENAMIENTO DE DATOS")
Console.WriteLine("1. Quicksort")
Console.WriteLine("2. Mtodo Burbuja")
Console.Write("Escoger Opcin: ")
Op = Console.ReadLine
Return Op
End Function
Sub orden1(ByRef n As Integer)
Console.Clear()
Console.WriteLine("Ordenamiento por Quicksort")
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("Ingrese el nmero de datos: ")
n = Console.ReadLine()
Console.WriteLine(" ")
Dim vector(n) As Integer
Dim i As Integer
If 0 < n And n < 10000000000 Then
For i = 1 To n
Console.ForegroundColor = ConsoleColor.Cyan
Console.Write("Ingrese el elemento {0}: ", i)
vector(i) = Console.ReadLine()
Next
Else
Console.Write("Ingrese Nmeros: ")
End If
quicksort(vector, 0, n)
mostrar1(vector, n)
End Sub
Sub quicksort(ByRef vector() As Integer, ByVal inicio
As Integer, ByVal fin As Integer)
Dim izq, der, pos, aux As Integer
Dim band As Integer
izq = inicio
der = fin
pos = inicio
band = 1
Grupo: APPLE
While (band = 1)
band = 0
While (vector(pos) <= vector(der) And pos <> der)
der = der - 1
End While
If pos <> der Then
aux = vector(pos)
vector(pos) = vector(der)
vector(der) = aux
pos = der
While (vector(pos) >= vector(izq) And pos <> izq)
izq = izq + 1
End While
If (pos <> izq) Then
band = 1
aux = vector(pos)
vector(pos) = vector(izq)
vector(izq) = aux
pos = izq
End If
End If
End While
If (pos - 1) > inicio Then
quicksort(vector, inicio, (pos - 1))
End If
If (fin > (pos + 1)) Then
quicksort(vector, (pos + 1), fin)
End If
End Sub
Sub mostrar1(ByRef vect() As Integer, ByVal n As Integer)
Dim i As Integer
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Yellow
For i = 1 To n
Console.WriteLine("Posiciones: {0} - Nmero: {1}", i, vect(i))
Next
Console.ReadLine()
End Sub
Sub orden2(ByVal n As Integer)
Console.Clear()
Console.WriteLine("Ordenamiento por Mtodo Burbuja")
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Red
Console.Write("Ingrese el nmero de datos:")
n = Console.ReadLine()
Console.WriteLine(" ")
Dim vector(n) As Integer
Dim i As Integer
If 0 < n And n < 10000000000 Then
For i = 1 To n
Console.ForegroundColor = ConsoleColor.Cyan
Console.Write("Ingrese el elemento {0}: ", i)
vector(i) = Console.ReadLine()
Next
Else
Grupo: APPLE
PILAS:
Module Module1
Grupo: APPLE
Grupo: APPLE
10
COLAS:
Module Module1
Sub Crear(ByRef Nombre() As String, ByRef ni As Single)
Dim x As Integer
For x = 0 To ni - 1
Console.Write("Ingresar nombre: ")
Nombre(x) = Console.ReadLine()
Next
End Sub
Sub Mostrar(ByVal Nombre() As String, ByVal ni As Single)
Dim x As Integer
For x = 0 To ni - 1
Console.WriteLine(" {0} ocupa el espacio {1} ", Nombre(x), x + 1)
Next
End Sub
Sub Ingresar(ByVal Nombre() As String, ByVal ni As Single, ByVal nf As Single)
nf = ni + 1
Console.WriteLine("Ingresar nombre: ")
Nombre(nf - 1) = Console.ReadLine()
Mostrar(Nombre, nf - 1)
End Sub
Sub Menu(ByVal Nombre() As String, ByVal ni As Single, ByVal nf As Single)
Dim op As Integer
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine(" 1. CREAR ")
Console.WriteLine(" 2. MOSTRAR ")
Console.WriteLine(" 3. INGRESAR ")
Console.WriteLine(" 4. FIN ")
Console.Write("Ingrese Opcin: ")
op = Console.ReadLine()
Console.WriteLine(" ")
Console.ForegroundColor = ConsoleColor.Cyan
Grupo: APPLE
11
Grupo: APPLE
12