用VB语言,怎么编写以下这个程序:随机生成10个100到200之间的整数,并判断其中的素数??

如题所述

Option Explicit On
Option Strict On

Imports System

Module Program
Sub Main()
Dim r As New Random(Date.Now.Millisecond)
Dim j,k,len,n,a(9),ssh(9) As Integer

len=0
Console.WriteLine("随机生成的10个100到200之间的整数是:")
For i As Integer=0 To 9
a(i)=r.[Next](100,201)
For j=0 To i-1
If a(j)=a(i) Then
Exit For
End If
Next
If j>=i Then
n=CInt(Math.Sqrt(a(i)))
For k=2 To n
If 0=a(i) Mod k Then
Exit For
End If
Next
If k>n Then
ssh(len)=a(i)
len+=1
End If
End If
Console.Write("{0} ",a(i))
Next
Console.WriteLine()
If len>0 Then
Console.WriteLine("其中素数有:")
For i As Integer=0 To len-1
Console.Write("{0} ",ssh(i))
Next
Else
Console.WriteLine("这10个整数中没有一个是素数")
End If
Console.WriteLine()
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
End Sub
End Module
温馨提示:答案为网友推荐,仅供参考