Imports System
Public Class Program
Friend Shared Function isPrime(ByVal num As Integer) As Boolean
For i As Integer = 2 To num / 2
If num Mod i = 0 Then
Return False
End If
Next
Return True
End Function
Public Shared Sub fill_matrix_with_prime_number(matrix(, ) As Integer)
Dim rows As Integer = matrix.GetLength(0)
Dim cols As Integer = matrix.GetLength(1)
Dim total As Integer = rows * cols
Dim result As Integer() = New Integer(total - 1) {}
Dim index As Integer = 0
Dim num As Integer = 2
While index < total
If isPrime(num) = True Then
result(index) = num
index += 1
End If
num += 1
End While
index = 0
For i As Integer = 0 To rows - 1
For j As Integer = 0 To cols - 1
matrix(i, j) = result(index)
index += 1
Next
Next
End Sub
Public Shared Sub Main(ByVal args As String())
Dim rows As Integer = 4, cols As Integer = 5
Dim matrix(rows - 1, cols - 1) As Integer
fill_matrix_with_prime_number(matrix)
For i As Integer = 0 To rows - 1
For j As Integer = 0 To cols - 1
Console.Write("{0,3:D}", matrix(i, j))
Next
Console.WriteLine()
Next
End Sub
End Class
' run:
'
' 2 3 5 7 11
' 13 17 19 23 29
' 31 37 41 43 47
' 53 59 61 67 71
'