Professional Documents
Culture Documents
Principio de Recursividad
Principio de Recursividad
EJEMPLO 1
CODIGO:
Module Module1
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single,
ByVal y2 As Single) As Single
distancia = CSng(Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)))
End Function
Sub linea(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)
Dim cx, cy As Integer
Console.SetCursorPosition(x1, y1)
Console.Write("*")
Console.SetCursorPosition(x2, y2)
Console.Write("*")
If distancia(x1, y1, x2, y2) >= 2 Then
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
linea(x1, y1, cx, cy)
linea(cx, cy, x2, y2)
End If
End Sub
Sub Main()
Dim x1, y1, x2, y2, x3, y3 As Integer
x1 = 20 : y1 = 22
x2 = 40 : y2 = 2
x3 = 60 : y3 = 22
Console.ForegroundColor = 9
linea(x1, y1, x2, y2)
Console.ForegroundColor = 10
linea(x2, y2, x3, y3)
Console.ForegroundColor = 12
linea(x3, y3, x1, y1)
Console.ReadLine()
End Sub
End Module
IMAGEN:
EJEMPLO 2:
CODIGO:
Module Module1
End Function
Console.SetCursorPosition(x1, y1)
Console.Write("*")
Console.SetCursorPosition(x2, y2)
Console.Write("*")
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
End If
End Sub
Sub Main()
x2 = 20 : y2 = 5
x3 = 5 : y3 = 5
x4 = 5 : y4 = 20
Console.ForegroundColor = 9
Console.ForegroundColor = 10
Console.ForegroundColor = 12
Console.ForegroundColor = 11
Console.ForegroundColor = 8
End Sub
End Module
IMAGEN:
EJERCICIO:
Graficar (Líneas, Barras y Texto) Valores por la Derecha con VISUAL BASIC
Se trata de una pequeña aplicación que implementa una forma de Graficar Valores
con Inicio por la Derecha.
CÓDIGO:
End Sub
End Class
IMAGENES DE PRUEBA:
METODOS NÚMERICOS:
Gráficar la función en console Visual Basic.
CÓDIGO:
Module Module1
Function f(ByVal x As Single) As Single
Return (x - 1) * (x) * (x - 3)
End Function
Sub main()
x += dx
End While
area = Trapecial(0, 1, 100) + Math.Abs(Trapecial(1, 3, 100))
Console.WriteLine("==============================")
Console.WriteLine("")
Console.WriteLine("El Area sombreada es {0} ", area)
Dim cx As Single = 40
Dim cy As Single = 20
Dim ex As Single = 6
Dim ey As Single = -6
Console.SetCursorPosition(cx, cy)
For x = 1 To 70
Console.SetCursorPosition(CInt(x), cy)
Console.WriteLine("-")
Next
For y = 10 To 35
Console.SetCursorPosition(cx, CInt(y))
Console.WriteLine("|")
Next
For x = li To ls Step dx / 20
y = f(x)
Console.SetCursorPosition(CInt(cx + x * ex), CInt(cy + y * ey))
Console.WriteLine("*")
Next
Console.ReadLine()
End Sub
End Module
IMAGEN DE PRUEBA:
EJEMPLO 2:
CODIGO
Module Module1
Function f(ByVal x As Single) As Single
Return (x - 1) * (x - 3) * (x - 2)
End Function
Sub main()
x += dx
End While
area = Math.Abs(Trapecial(1, 2, 100)) + Math.Abs(Trapecial(2, 3, 100))
Console.ForegroundColor = 10
Console.WriteLine("==============================")
Console.WriteLine("")
Console.WriteLine("El Area sombreada es {0} ", area)
Dim cx As Single = 40
Dim cy As Single = 20
Dim ex As Single = 12
Dim ey As Single = -12
Console.SetCursorPosition(cx, cy)
REM coordenadas
Console.ForegroundColor = CType(13, ConsoleColor)
For x = 1 To 70
Console.SetCursorPosition(CInt(x), cy)
Console.WriteLine("-")
Next
For y = 10 To 35
Console.SetCursorPosition(cx, CInt(y))
Console.WriteLine("|")
Next
Console.ForegroundColor = CType(10, ConsoleColor)
For x = li To ls Step dx / 20
y = f(x)
Console.SetCursorPosition(CInt(cx + x * ex), CInt(cy + y * ey))
Console.WriteLine("*")
Next
Console.ReadLine()
End Sub
End Module
IMAGEN: