You are on page 1of 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