Diseñar un algoritmo que permita calcular las 5 primeras parejas de números primos gemelos(dos números son primos gemelos si además de ser números primos, la diferencia entre ellos es exactamente dos).
Codigo Fuente en Visual Basic
Public Class Form1 Dim p() As Integer Dim cad As String = "" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ReDim p(10) Dim b As Integer = 0 For k As Integer = 2 To 36 Dim a As Integer = 0 For i As Integer = 1 To k If (k Mod i = 0) Then a = a + 1 End If Next i If (a <> 2) Then Else p(b) = k b = b + 1 End If Next k For x As Integer = 1 To b - 2 If (p(x + 1) - p(x) = 2) Then cad = cad + " " + Trim(p(x + 1)) + " y " + Trim(p(x)) + " Son numeros primos gemelos" & vbCrLf End If Next x TextBox1.Text = cad End Sub End Class
0 comentarios:
Publicar un comentario