Bienvenidos al Chivolero

En este espacio están algunos ejemplos sobre algunos temas básicos y muy importanes en la programación.

Este espacio es exclusivo para personas que sepan y que no solamente sepan el famoso 'copy/paste'

sábado, 17 de mayo de 2008

Matriz Multiplicación

Public Class Form3

Dim numeros1(1, 1) As Integer

Dim numeros2(1, 1) As Integer

Dim c1, c2 As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

For c1 = 0 To 1

For c2 = 0 To 1

numeros1(c2, c1) = InputBox("Ingrese un numero entero")

Next

Next

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

For c1 = 0 To 1

For c2 = 0 To 1

numeros2(c2, c1) = InputBox("Ingrese un numero entero")

Next

Next

For c1 = 0 To 1

For c2 = 0 To 1

MsgBox("La multiplicación de los vectores es " & numeros1(c2, c1) * numeros2(c2, c1))

Next

Next

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Form4.Show()

End Sub

End Class

Matriz Suma

Public Class Form1

Dim acumulador As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim numeros(2, 2) As Integer

Dim c1, c2 As Integer

For c1 = 0 To 2

For c2 = 0 To 2

numeros(c2, c1) = InputBox("Ingrese un numero entero")

Next

Next

For c1 = 0 To 2

For c2 = 0 To 2

MsgBox("Valores ingresados " & numeros(c2, c1))

Next

Next

For c1 = 0 To 2

For c2 = 0 To 2

acumulador = acumulador + numeros(c2, c1)

Next

Next

MsgBox("La suma de todos los números es " & acumulador)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Form2.Show()

End Sub

End Class

Vector

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim numeros(0 To 4) As Integer

Dim c1, c2, c3, acumulador As Integer

For c1 = 0 To 4

numeros(c1) = InputBox("Ingrese un numero entero")

Next

For c2 = 0 To 4

MsgBox("El numero ingresado fue " & numeros(c2))

Next

For c3 = 0 To 4

acum = acum + numeros(c3)

Next

MsgBox("La suma del vector es " & acum)

Label2.Text = acum

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Form2.Show()

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

End Class

sábado, 10 de mayo de 2008

RECURSIVIDAD: Combinatorio

Public Class Form6
Dim a, b, c, e As Integer
Function combinatorio(ByVal b As Integer, ByVal e As Integer) As Integer
If e = 0 Or e = b Then
Return 1
Else
If e = 1 Then
Return b
Else
Return combinatorio(b - 1, e) + combinatorio(b - 1, e - 1)
End
If
End If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
c = TextBox2.Text
Dim d As Integer = combinatorio(a, c)
Label2.Text = d
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form7.Show()
End Sub

End Class

RECURSIVIDAD: POTENCIA

Public Class Form4
Dim a, b, c, e As Integer

Function potencia(ByVal b As Integer, ByVal e As Integer) As Integer
If e = 0 Then
Return 1
End If

If e = 1 Then
Return b
Else
Return b * potencia(b, e - 1)
End
If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
c = TextBox2.Text
Dim d As Integer = potencia(a, c)
Label2.Text = d
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form5.Show()
End Sub

End
Class

jueves, 8 de mayo de 2008

FUNCION QUE RECIBE UN ARREGLO COMO PARAMETRO

Public Class Form3
Dim numeros(4) As Integer
Dim c1, x As Integer

Public Function sumar(ByVal x() As Integer) As Integer
Dim i, j As Integer
For Each i In x
j += i
Next
sumar = j
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For c1 = 0 To 4
numeros(c1) = InputBox("Ingrese un numero entero")
Next
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MsgBox(sumar(numeros))
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form4.Show()
End Sub

End
Class

RECURSIVIDAD: FIBONACCI

Public Class Form2
Dim a, b, N As Integer

Function Fibonacci(ByVal N As Integer) As Integer
If N = 0 Or N = 1 Then
Return N
Else
Return Fibonacci(N - 1) + Fibonacci(N - 2)
End If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = Fibonacci(a)
Label2.Text = b
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form3.Show()
End Sub

End
Class

RECURSIVIDAD: FACTORIAL

Public Class Form1
Dim a, b, N As Integer
Function Factorial(ByVal N As Integer) As Integer

If N <= 1 Then
Return 1
Else

Return Factorial(N - 1) * N
End If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = Factorial(a)
Label2.Text = b
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form2.Show()
End Sub

End Class

miércoles, 7 de mayo de 2008

Función Par

Public Class Form6
Dim a, b As Integer

Function par(ByVal a As Integer, ByVal b As Integer) As String
If a Mod 2 = 0 Then
par = (a & " es numero par ")
Else

par = (a & " no es numero par ")
End If

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
Label3.Text = par(a, b)
End Sub

End
Class

Función Primo

Public Class Form4
Dim a, i, c As Integer

Function mul(ByVal a As Integer) As String
c = 0
For i = 1 To 1000
If (a Mod i = 0) Then
c += 1
End If
Next
If c >= 3 Then
mul = "no es primo"
Else
mul = "es primo"
End
If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
Label3.Text = mul(a)

End Sub
End
Class

Función Múltiplo

Public Class Form3
Dim a, b As Integer

Function mul(ByVal a As Integer, ByVal b As Integer) As String
If b Mod a = 0 Then
mul = (b & " es multiplo de " & a)
Else
mul = (b & " no es multiplo de " & a)
End
If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
Label3.Text = mul(a, b)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form4.Show()
End Sub

End
Class

Función Hipotenusa

Public Class Form5
Dim a, b As Integer

Function hip(ByVal a As Integer, ByVal b As Integer)
hip = Math.Sqrt((a * a) + (b * b))
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
Label3.Text = hip(a, b)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form6.Show()
End Sub

End
Class

Función Menor

Public Class Form2
Dim a, b, c, d As Integer

Function menor(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) AsInteger
If (a <>
menor = a
ElseIf (b <>
menor = b
ElseIf (c <>
menor = c
End If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
Label3.Text = menor(a, b, c)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
form3.show()
End Sub
End Class

Función Raíz Cuadrada

Public Class Form4
Dim a, b As Integer
Function raiz(ByVal a As Integer) As Integer
raiz = Math.Sqrt(a)
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = raiz(a)
Label3.Text = b
End Sub
End
Class

Función Mayor De Tres

Public Class Form3
Dim a, b, c As Integer

Function mayor(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) AsInteger
Dim d As Integer = a
If b > d Then
d = b

End If
If c > d Then
d = c
End If
mayor = d
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
Dim d As Integer = mayor(a, b, c)
Label3.Text = d

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form4.Show()
End Sub

End
Class

Función Potencia

Public Class Form2
Dim a, b, c As Integer

Function potencia(ByVal a As Integer, ByVal b As Integer) As Integer
potencia = 1
For c = 1 To b
potencia = potencia * a
Next

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
Dim d As Integer = potencia(a, b)
Label3.Text = d

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form3.Show()
End Sub

End
Class

Función Cuadrado

Public Class Form1
Dim a As Integer
Function cuadrado(ByVal a As Integer) As Integer
cuadrado = a * a
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As system.EventArgs) Handles Button1.Click
a = TextBox1.Text
Dim B As Integer = cuadrado(a)
Label3.Text = B
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form2.Show()
End Sub

End Class