-
-
Save parzibyte/48b0ec90214e11bb8f1e99414e3c8f05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System | |
Module Program | |
Sub Ejercicio1() | |
Dim edad As Integer | |
Console.WriteLine("Escribe tu edad:") | |
edad = Convert.ToInt64(Console.ReadLine()) | |
If edad < 18 Then | |
Console.WriteLine("Menor de edad") | |
Else | |
Console.WriteLine("Mayor de edad") | |
End If | |
End Sub | |
Sub Ejercicio2() | |
Dim numero As Integer | |
Console.WriteLine("Escribe un número:") | |
numero = Convert.ToInt64(Console.ReadLine()) | |
If numero < 0 Then | |
Console.WriteLine("Negativo") | |
Else | |
Console.WriteLine("Positivo") | |
End If | |
End Sub | |
Sub Ejercicio3() | |
Dim monto As Double | |
Console.WriteLine("Escribe el monto de compra:") | |
monto = Convert.ToDouble(Console.ReadLine()) | |
Dim porcentajeDescuento As Double | |
If monto = 1000 Then | |
porcentajeDescuento = 0.3 | |
ElseIf monto = 500 Then | |
porcentajeDescuento = 0.2 | |
ElseIf monto = 250 Then | |
porcentajeDescuento = 0.1 | |
Else | |
porcentajeDescuento = 0.05 | |
End If | |
Dim descuento As Double = monto * porcentajeDescuento | |
Dim total As Double = monto - descuento | |
Console.WriteLine("Descuento aplicado: {0} ({1} %) Total: {2}", descuento, porcentajeDescuento * 100, total) | |
End Sub | |
Sub Ejercicio4() | |
Dim tipoPoliza As String | |
Console.WriteLine("Escribe el tipo de póliza [A/B]:") | |
tipoPoliza = Console.ReadLine() | |
Dim cuotaBase As Double = 500 | |
Dim porcentajeAumento As Double = 0.0 | |
If tipoPoliza = "B" Then | |
cuotaBase = 250 | |
End If | |
Console.WriteLine("¿Bebe alcohol? [s/n]") | |
If Console.ReadLine() = "s" Then | |
porcentajeAumento += 0.1 | |
End If | |
Console.WriteLine("¿Utiliza lentes? [s/n]") | |
If Console.ReadLine() = "s" Then | |
porcentajeAumento += 0.05 | |
End If | |
Console.WriteLine("¿Padece alguna enfermedad? [s/n]") | |
If Console.ReadLine() = "s" Then | |
porcentajeAumento += 0.05 | |
End If | |
Console.WriteLine("Introduzca la edad: ") | |
If Convert.ToInt64(Console.ReadLine()) > 40 Then | |
porcentajeAumento += 0.2 | |
Else | |
porcentajeAumento += 0.1 | |
End If | |
Dim cargoExtra As Double = cuotaBase * porcentajeAumento | |
Dim cuotaFinal As Double = cuotaBase + cargoExtra | |
Console.WriteLine("Monto base: {0}. Cargo extra: {1} ({2} %). Cuota final: {3}", cuotaBase, cargoExtra, porcentajeAumento * 100, cuotaFinal) | |
End Sub | |
Sub Ejercicio5() | |
Console.WriteLine("Ingrese el valor de n: ") | |
Dim n As Integer = Convert.ToInt64(Console.ReadLine()) | |
Dim suma As Integer = 0 | |
For i = 1 To n | |
Console.Write("{0}", i) | |
suma += i | |
If i < n Then | |
Console.Write("+") | |
Else | |
Console.Write("=") | |
End If | |
Next | |
Console.WriteLine(suma) | |
End Sub | |
Sub Ejercicio6() | |
Console.WriteLine("Ingrese el número para mostrar la tabla de multiplicar:") | |
Dim numeroDeTabla As Integer = Convert.ToInt64(Console.ReadLine()) | |
Dim suma As Integer = 0 | |
For i = 1 To 10 | |
Dim resultado As Integer = i * numeroDeTabla | |
Console.WriteLine("{0} x {1} = {2}", numeroDeTabla, i, resultado) | |
Next | |
End Sub | |
Sub Ejercicio7() | |
Dim incremento As Double = 3 | |
Console.WriteLine("Ingrese ahorro mensual: ") | |
Dim ahorro As Double = Convert.ToDouble(Console.ReadLine()) | |
Dim meses = New String() {"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"} | |
Dim total As Double = ahorro | |
For Each mesActual As String In meses | |
Console.WriteLine("{0} ${1}", mesActual, total) | |
total += ahorro | |
Next | |
End Sub | |
Sub Ejercicio8() | |
Console.WriteLine("Ingrese depósito mensual:") | |
Dim depositoMensual As Double = Convert.ToDouble(Console.ReadLine()) | |
Dim depositoAnual As Double = depositoMensual * 12 | |
Console.WriteLine("Ingrese la cantidad de años:") | |
Dim cantidadAnios As Double = Convert.ToDouble(Console.ReadLine()) | |
Dim interes As Double = 0.15 | |
For i = 1 To cantidadAnios | |
Dim aumento = depositoAnual * interes | |
depositoAnual += aumento | |
Console.WriteLine("Año {0} inversión final: {1}", i, depositoAnual) | |
Next | |
End Sub | |
Sub Ejercicio9() | |
Dim calificaciones = New Double() {77, 10, 70, 100, 88, 58} | |
Dim mayor = calificaciones.ElementAt(0) | |
Dim menor = calificaciones.ElementAt(0) | |
Dim sumatoria As Double = 0.0 | |
For Each calificacion In calificaciones | |
sumatoria += calificacion | |
If calificacion > mayor Then | |
mayor = calificacion | |
End If | |
If calificacion < menor Then | |
menor = calificacion | |
End If | |
Next | |
Dim promedio As Double = sumatoria / calificaciones.Length | |
Dim apruebaCon As Double = 70 | |
Console.WriteLine("Nota mayor: {0}", mayor) | |
Console.WriteLine("Nota menor: {0}", menor) | |
Console.WriteLine("Promedio: {0}", promedio) | |
If promedio > apruebaCon Then | |
Console.WriteLine("Aprueba") | |
Else | |
Console.WriteLine("NO arueba") | |
End If | |
End Sub | |
Sub Ejercicio10() | |
Dim cantidadEmpleados As Integer = 5 | |
Dim nombres(cantidadEmpleados) As String | |
Dim horasTrabajadas(cantidadEmpleados) As Double | |
Dim salarios(cantidadEmpleados) As Double | |
For i = 0 To cantidadEmpleados - 1 | |
Console.WriteLine("Ingrese el nombre del empleado #{0}", i + 1) | |
nombres.SetValue(Console.ReadLine(), i) | |
Console.WriteLine("Ingrese las horas trabajadas diarias de empleado #{0}", i + 1) | |
horasTrabajadas.SetValue(Convert.ToDouble(Console.ReadLine()), i) | |
Console.WriteLine("Ingrese el salario por hora trabajada del empleado #{0}", i + 1) | |
salarios.SetValue(Convert.ToDouble(Console.ReadLine()), i) | |
Next | |
Dim diasLaborales As Double = 5 | |
Dim nombreEmpleadoMasTrabajador = "" | |
Dim horasEmpleadoMasTrabajador = 0 | |
For i = 0 To cantidadEmpleados - 1 | |
Dim nombre As String = nombres.ElementAt(i) | |
Dim horasTrabajadasEmpleado As String = horasTrabajadas.ElementAt(i) | |
Dim salario As String = salarios.ElementAt(i) | |
Dim horasTrabajadasSemana As Double = horasTrabajadasEmpleado * diasLaborales | |
Dim salarioSemanal As Double = horasTrabajadasSemana * salario | |
If horasTrabajadasSemana > horasEmpleadoMasTrabajador Then | |
horasEmpleadoMasTrabajador = horasTrabajadasSemana | |
nombreEmpleadoMasTrabajador = nombre | |
End If | |
Console.WriteLine("Empleado {0} trabaja {1} horas a la semana, salario semanal es ${2}", nombre, horasTrabajadasSemana, salarioSemanal) | |
Next | |
Console.WriteLine("Empleado que trabaja más horas: {0} (trabajó {1} horas)", nombreEmpleadoMasTrabajador, horasEmpleadoMasTrabajador) | |
End Sub | |
Function EsMayorDeEdad(edad As Integer) As Boolean | |
If edad < 18 Then | |
Return False | |
Else | |
Return True | |
End If | |
End Function | |
Sub Ejercicio11() | |
Console.WriteLine("Ingresa tu edad: ") | |
Dim edad As Integer = Convert.ToInt32(Console.ReadLine()) | |
If EsMayorDeEdad(edad) Then | |
Console.WriteLine("Mayor de edad") | |
Else | |
Console.WriteLine("Menor de edad") | |
End If | |
End Sub | |
Function operaciones(numero1 As Double, numero2 As Double, operacion As String) As Double | |
If operacion = "suma" Then | |
Return numero1 + numero2 | |
End If | |
If operacion = "resta" Then | |
Return numero1 - numero2 | |
End If | |
If operacion = "multiplicación" Then | |
Return numero1 * numero2 | |
End If | |
End Function | |
Sub Ejercicio12() | |
Console.WriteLine("Suma: ") | |
Console.WriteLine(operaciones(1, 2, "suma")) | |
Console.WriteLine("Resta: ") | |
Console.WriteLine(operaciones(1, 2, "resta")) | |
Console.WriteLine("Multiplicación: ") | |
Console.WriteLine(operaciones(1, 2, "multiplicación")) | |
End Sub | |
Function obtenerMayor(numeros As Integer()) As Integer | |
Dim mayor As Integer = numeros.ElementAt(0) | |
For Each numero In numeros | |
If numero > mayor Then | |
mayor = numero | |
End If | |
Next | |
Return mayor | |
End Function | |
Sub Ejercicio13() | |
Dim numeros = New Integer() {40, 5, 2, 1, 9} | |
Dim mayor As Integer = obtenerMayor(numeros) | |
Console.WriteLine("Mayor: {0}", mayor) | |
End Sub | |
Sub Main(args As String()) | |
Ejercicio1() | |
Ejercicio2() | |
Ejercicio3() | |
Ejercicio4() | |
Ejercicio5() | |
Ejercicio6() | |
Ejercicio7() | |
Ejercicio8() | |
Ejercicio9() | |
Ejercicio10() | |
Ejercicio11() | |
Ejercicio12() | |
Ejercicio13() | |
End Sub | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment