Ejercicio
Varias operaciones
Objetivo
Escriba un programa en Visual Basic para imprimir en pantalla el resultado de sumar, restar, multiplicar y dividir dos números escritos por el usuario. El resto de la división también debe mostrarse.
Podría verse así:
Introduzca un número: 12
Introduzca otro número: 3
12 + 3 = 15
12 - 3 = 9
12 x 3 = 36
12 / 3 = 4 <
12 mod 3 = 0
Código
' Import the System namespace to use Console class
Imports System
Public Class Program
' Main subroutine, entry point of the program
Public Shared Sub Main()
' Prompt the user to enter the first number
Console.Write("Enter the first number: ")
Dim number1 As Integer = Convert.ToInt32(Console.ReadLine())
' Prompt the user to enter the second number
Console.Write("Enter the second number: ")
Dim number2 As Integer = Convert.ToInt32(Console.ReadLine())
' Perform addition, subtraction, multiplication, division, and remainder
Dim sum As Integer = number1 + number2
Dim difference As Integer = number1 - number2
Dim product As Integer = number1 * number2
Dim quotient As Integer = number1 \ number2
Dim remainder As Integer = number1 Mod number2
' Display the results
Console.WriteLine("The result of adding the numbers is: " & sum)
Console.WriteLine("The result of subtracting the numbers is: " & difference)
Console.WriteLine("The result of multiplying the numbers is: " & product)
Console.WriteLine("The result of dividing the numbers is: " & quotient)
Console.WriteLine("The remainder of the division is: " & remainder)
End Sub
End Class