Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/12/2007, 20:52
Avatar de seba123neo
seba123neo
 
Fecha de Ingreso: febrero-2007
Ubicación: Esperanza, Santa Fe
Mensajes: 1.046
Antigüedad: 18 años, 2 meses
Puntos: 19
Re: números primos

Hola,fijate si te sirve esto:

Código:
Public Class Form1

    Dim x As Integer
    Dim i As Integer
    Dim a As Integer

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        i = Val(TextBox1.Text)
        a = Val(TextBox2.Text)
        Label1.Text = ""

        For x = i To a
            If Primo(x) = True Then
                Label1.Text = Label1.Text & x & " "
            End If
        Next

    End Sub

    Function Primo(ByVal Nro As Integer) As Boolean
        Dim i As Integer
        For i = 2 To Nro / 2
            If Nro Mod i = 0 Then
                Primo = False
                Exit Function
            End If
        Next
        Primo = True
    End Function

End Class
tambien le podrias poner que en el text1 no pueda escribir el 0 o el 1,ya que el primer primo es el 2.

saludos.
__________________
" Todos Somos Ignorantes; lo que pasa es que no todos ignoramos las mismas cosas " - Albert Einstein