|
|||||||
|
|
|
|||||
|
|
|||||||
Documento pdf recomendado para resolver la guía : Introducción a Basic
1) Usar los operadores de división entera y real, para dividir dos numeros enteros ingresados por medio de InputBox y asignar el resultado a una variable de tipo Integer y otra de tipo Double.
Además se debe mostrar el resultado de dichas operaciones si se aplican las
siguientes funciones de redondeo y truncación :
Int(number) : Trunca un número a un valor entero igual o inferior
Fix(number) : Trunca un número no tomando en cuenta la parte decimal
Round(number [,numDigitos]) : Redondea un número
Int(1.2) = 1 , Int (-1.2) = -2 , Int(1.8) = 1 , Int(-1.8) = -2
Fix(1.2) = 1 , Fix (-1.2) = -1 , Fix(1.8) = 1 , Fix (-1.8) = -1
Round(1.2) = 1, Round (-1.2) = -1 , Round(1.8) = 2 , Round(-1.8) = -2
Round(4.567 , 2) = 4.57 , Round(4.5621 , 3) = 4.562
SOLUCIÓN
Dim a As Integer, b As Integer
Dim i As Integer, d As Double
Dim mensaje As String
a = InputBox("Ingrese numerador (entero) : ")
b = InputBox("Ingrese denominador (entero) : ")
'-----------------------------------------------
i = a / b
d = a / b
mensaje = "Dim i as Integer , Dim d as Double" & vbCrLf & vbCrLf & _
Str(a) & " / " & Str(b) & " = " & Str(a / b) & vbCrLf & vbCrLf & _
"i = " & Str(a) & " / " & Str(b) & " --> " & Str(i) & vbCrLf & _
"d = " & Str(a) & " / " & Str(b) & " --> " & Str(d) & vbCrLf
'------------------------------------------------
i = Int(a / b)
d = Int(a / b)
mensaje = mensaje & vbCrLf & _
"i = Int(" & Str(a) & " / " & Str(b) & ") --> " & Str(i) & vbCrLf & _
"d = Int(" & Str(a) & " / " & Str(b) & ") --> " & Str(d) & vbCrLf
'---------------------------------------------------
i = Fix(a / b)
d = Fix(a / b)
mensaje = mensaje & vbCrLf & _
"i = Fix(" & Str(a) & " / " & Str(b) & ") --> " & Str(i) & vbCrLf & _
"d = Fix(" & Str(a) & " / " & Str(b) & ") --> " & Str(d) & vbCrLf
'----------------------------------------------------
i = Round(a / b)
d = Round(a / b)
mensaje = mensaje & vbCrLf & _
"i = Round(" & Str(a) & " / " & Str(b) & ") --> " & Str(i) & vbCrLf & _
"d = Round(" & Str(a) & " / " & Str(b) & ") --> " & Str(d) & vbCrLf
'-----------------------------------------------------
i = a \ b
d = a \ b
mensaje = mensaje & vbCrLf & _
"i = " & Str(a) & " \ " & Str(b) & " --> " & Str(i) & vbCrLf & _
"d = " & Str(a) & " \ " & Str(b) & " --> " & Str(d) & vbTab & " ... (" & Format(d, "#.0") & ")"
MsgBox mensaje
SOLUCIÓN
Dim a As Integer, b As Integer, c As Integer
Dim numLados As Integer
For a = 1 To 3
For b = 1 To 3
For c = 1 To 3
If (a = b) Then
If (b = c) Then
numLados = 3
Else
numLados = 2
End If
Else
If (b = c) Then
numLados = 2
Else
If (c = a) Then
numLados = 2
Else
numLados = 0
End If
End If
End If
Select Case numLados
Case 0
Debug.Print "Escaleno" & Str(a) & Str(b) & Str(c)
Case 2
Debug.Print "Isoceles" & Str(a) & Str(b) & Str(c)
Case 3
Debug.Print "Equilatero" & Str(a) & Str(b) & Str(c)
End Select
Next c
Next b
Next a
3) Realizar un programa que permita leer un conjunto de notas, calificándolas una a una, para después
calcular su promedio.
SOLUCIÓN
Dim prom As Double, nota As Double, numNotas As Double
Dim i As Integer
prom = 0
numNotas = InputBox("Ingrese numero de notas a evaluar ej : 5,4 ")
' CRITERIOS DE EVALUACION
' -------------------------------
' nota < 3.0 --> muy mala
' 3.0 < nota < 4.0 --> mala
' 4.0 <= nota < 5.0 --> regular
' 5.0 <= nota < 6.0 --> buena
' 6.0 <= nota < 7.0 --> muy buena
' 7.0 --> excelente
For i = 1 To numNotas
nota = InputBox("Ingrese nota")
Select Case nota
Case Is < 3
MsgBox "Muy mala"
Case 3 To 3.9
MsgBox "Mala"
Case 4 To 4.9
MsgBox "Regular"
Case 5 To 5.9
MsgBox "Buena"
Case 6 To 6.9
MsgBox "Muy buena"
Case 7
MsgBox "Excelente"
End Select
prom = prom + nota
Next i
MsgBox "Promedio de notas : " & Round(prom / numNotas, 2)
4) Implementar la siguiente sumatoria
SOLUCIÓN
Dim dx As Double, dy As Double, sum As Double
sum = 1
For dx = -1 To 1 Step 0.1
For dy = -5 To 5 Step 1
If (dx <> 0 And dy <> 0) Then
sum = sum + Abs((dx + dy) ^ (dy))
End If
Next dy
Next dx
Debug.Print sum
5) Implementar el algoritmo que invierte un número entero
SOLUCIÓN
Dim num As Integer, numInv As Integer, divEntera As Integer
Dim resto As Integer
num = InputBox("Ingrese numero : ")
numInv = 0
divEntera = num
resto = 0
Do While (divEntera <> 0)
resto = divEntera Mod 10
divEntera = divEntera \ 10
numInv = numInv * 10 + resto
Loop
MsgBox "El numero " & Str(num) & " invertido es : " & Str(numInv)
6) Basandose en la tabla de operadores lógicos determinar el resultado de las expresiones mediante un programa
en Visual Basic
| X | Y | X And Y | X Or Y | Not X |
| False | False | False | False | True |
| False | True | False | True | True |
| True | False | False | True | False |
| True | True | True | True | False |
SOLUCIÓN
Dim Result As Boolean Result = (3 = 4) And (5 = 7) Debug.Print Result Result = (5 <> 5) Or (3 >= 0) Debug.Print Result Result = Not (7 < 5 Or Not (8 < 9)) Debug.Print Result Result = (Not (7 > 9) And (4 < 9)) Or (1 <> 1) And (6 < 8) Debug.Print Result
I) Determinar cuántos números palíndromes existen entre 11 y 3553.
(11 , 212 , 1661 , 3553 son palíndromes)
II) Determinar el porcentaje de números perfectos (suma de los divisores es igual al número ej: 6 = 1 + 2 + 3) que existen en los siguientes tramos :
tramo 1 : 1 ... 100
tramo 2 : 101 ... 199
tramo 3 : 199 ... 300
*nota : usar estructura de control Select Case para evaluar los tramos.