0% found this document useful (0 votes)
102 views1 page

Twin Prime Numbers

1) The document contains code to find twin prime numbers between 10 and 1000. 2) It uses arrays and loops to store prime numbers and check if consecutive numbers are prime. 3) It displays any twin prime pairs found between the given range.

Uploaded by

Agrippa Mungazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views1 page

Twin Prime Numbers

1) The document contains code to find twin prime numbers between 10 and 1000. 2) It uses arrays and loops to store prime numbers and check if consecutive numbers are prime. 3) It displays any twin prime pairs found between the given range.

Uploaded by

Agrippa Mungazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Imports System.

Console
Module Module1
Sub Main() 'program by Mungazi Mungazi
'display twin prime numbers between 10 and 1000
Dim prime(496) As Integer
Dim y As Integer = 0, x As Integer, diff As Integer
For x = 11 To 1000 Step 2
If x Mod 2 = 0 Or x Mod 3 = 0 Or x Mod 5 = 0 Or x Mod 7 = 0 Then
'x mod 2 = 0 has no effect on this particular code since x = 11
'is the starting value and there is the Step 2 increment
Else
While y < 496
prime(y) = x 'array to store prime numbers between 10 and 1000
y += 1
Exit While 'force loop to terminate before executing to completion
End While
End If
Next
For x = 0 To 495
If prime(x) And prime(x + 1) Then
diff = prime(x + 1) - prime(x)
If diff = 2 Then
WriteLine(prime(x) & " And " & prime(x + 1))
End If
Else
Exit For 'force loop to stop and reduce processor overheads
'there are only 227 prime numbers from 11 to 1000
'and only 70 twin prime numbers, the loop runs for 127 times and stop
'instead of 496 times dictated by the loop
End If
Next
ReadKey()
End Sub

End Module

You might also like