Pages

jueves, 31 de enero de 2013

Ingresar cinco números primos cualesquiera Codigo en Visual Basic - VB

Problema
Diseñar un algoritmo que permita ingresar 5  números primos cualesquiera.

Codigo Fuente en Visual Basic
Public Class Form1
    Dim d As Integer = 0
    Dim Primo(4) As Integer
    Dim cad As String = ""
    Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles Button1.Click
        Label2.Text = ""
        Dim a As Integer = 0
        Dim n As Integer
        n = TextBox1.Text
        If (d <> 5) Then
            For i As Integer = 1 To n
                If (n Mod i = 0) Then
                    a = a + 1
                End If
            Next i
            If (a = 2) Then
                Primo(d) = n
                d = d + 1
            Else
                Label2.Text = "No es primo ingrese otro numero"
            End If
        Else
            For q As Integer = 0 To 4
                cad = cad + " " + Trim(Primo(q))
            Next q
            TextBox2.Text = cad
        End If
    End Sub
End Class

0 comentarios:

Publicar un comentario