Sub main()
Dim opc As Integer
Do
opc = InputBox("1: Numeros" & vbCrLf & "2: Factorial" & vbCrLf & "3: Dias de mes" & vbCrLf & "4: Salir")
Select Case opc
Case 1: uno
Case 2: dos
Case 3: tres
End Select
Loop Until opc = 4
End Sub
Sub uno()
Dim numero As Integer
Dim mayor As Integer
Dim menor As Integer
Dim promedio As Double
Dim suma As Integer
Dim n As Integer
Dim sw As Integer
suma = 0
sw = 0
n = 0
Do
numero = InputBox("Ingrese numero: ")
If sw = 0 Then
mayor = numero
menor = numero
sw = 1
End If
If numero <> 0 Then
n = n + 1
End If
If numero > mayor Then
mayor = numero
End If
If numero < menor And numero <> 0 Then
menor = numero
End If
suma = suma + numero
Loop Until numero = 0
If n <> 0 Then
promedio = suma / n
End If
MsgBox ("Cantidad: " & n & vbCrLf & "Mayor: " & mayor & vbCrLf & "Menor: " & menor & vbCrLf & "Promedio: " & promedio)
End Sub
Function factorial(n As Integer) As Integer
Dim fact As Integer
Dim i As Integer
fact = 1
If (n = 0) Then
fact = 1
Else
For i = 1 To n
fact = fact * i
Next
End If
factorial = fact
End Function
Sub dos()
Dim numero As Integer
Dim fact As Integer
numero = InputBox("Ingrese numero: ")
If numero < 0 Then
MsgBox ("No hay factorial de negativos")
Else
fact = factorial(numero)
MsgBox ("Factorial de " & numero & " es " & fact)
End If
End Sub
Sub cantidad(mes As String, ByRef c As Integer)
Select Case mes
Case "enero": c = 31
Case "febrero": c = 28
Case "marzo": c = 31
Case "abril": c = 30
Case "mayo": c = 31
Case "junio": c = 30
Case "julio": c = 31
Case "agosto": c = 31
Case "setiembre": c = 30
Case "octubre": c = 31
Case "noviembre": c = 30
Case "diciembre": c = 31
End Select
End Sub
Sub tres()
Dim mes As String
Dim dias As Integer
dias = 0
Do
mes = InputBox("Ingrese mes: ")
cantidad mes, dias
Loop Until dias > 0
MsgBox (mes & " tiene " & dias & " dias")
End Sub
No hay comentarios:
Publicar un comentario