Ejercicio
Número primo
Objetivo
Escribe un programa en Visual Basic que pida al usuario un número entero y responda si es un número primo o no.
Código
Imports System
Public Class exercise46
Public Shared Sub Main()
Dim number As Integer
Dim dividers As Integer = 0
Console.Write("Enter a number: ")
number = Convert.ToInt32(Console.ReadLine())
For i As Integer = 1 To number
If number Mod i = 0 Then dividers += 1
Next
If dividers = 2 Then
Console.WriteLine("The number is prime")
Else
Console.WriteLine("The number is not prime")
End If
End Sub
End Class