Ejercicio
Función IsPrimeTarea
Objetivo
Cree una función denominada "IsPrime", que recibe un número entero y vuelve a ser true si es primo, o false si no lo es:
if (isPrime(127)) ...
Código
Imports System
Public Class exercise111
Public Shared Function IsPrime(ByVal n As Integer) As Boolean
For i As Integer = 2 To n - 1
If n Mod i = 0 Then Return False
Next
Return True
End Function
Public Shared Sub Main()
If IsPrime(127) Then
Console.WriteLine("127 is a prime number")
Else
Console.WriteLine("127 is NOT a prime number")
End If
If IsPrime(1000003) Then
Console.WriteLine("1000003 is a prime number")
Else
Console.WriteLine("1000003 is NOT a prime number")
End If
End Sub
End Class