Vb编程:求100-999之间的所有素数

求100-999之间的所有素数,并在窗体上输出
要求:自定义一个过程判断一个数是否是素数
(答案正确追加30以上)

第1个回答  2008-06-03
我只会判断是不是素数,因为我是个VB菜鸟.
希望你能用得上.

Private Sub Command1_Click()
n = Val(Text1.Text)
a = 0

For i = 2 To n - 1
If (n Mod i) = 0 Then a = 1
If a = 1 Then Exit For
Next i

If a = 0 Then
Text2.Text = Text2.Text & n & "是素数" & vbCrLf
Else
Text2.Text = Text2.Text & n & "不是素数" & vbCrLf
End If
Text1.Text = ""
Text1.SetFocus
End Sub

Private Sub Form_Load()
Me.Caption = "判断是否素数"
Command1.Caption = "判断是否素数"
Command1.Default = True
Text1.Text = ""
Text1.TabIndex = 0
Text2.Text = ""
End Sub
第2个回答  2008-06-03
Private Sub Command1_Click()
For i = 100 To 999
If IsPrime(i) Then
n = n + 1
Print i;
If n Mod 10 = 0 Then Print
End If
Next i
End Sub
Public Function IsPrime(ByVal num As Long) As Boolean
Dim m As Long
m = Sqr(num)
IsPrime = True
For i = 2 To m
If num Mod i = 0 Then
IsPrime = False
Exit For
End If
Next i
End Function本回答被提问者采纳

从100到999的质数vb怎样写程序
Dim i As Integer, j As Integer, n As Integer Dim b As Boolean n = 0 For i = 100 To 999 b = True For j = 2 To i \/ 2 If i Mod j = 0 Then b = False Exit For End If Next j If b Then n = n + 1 Next i MsgBox "有" & n & "个质数"...

vb编判断输出100~999之间的素数,在程序的空白处填上合适的语句,使得程 ...
vbcrlf : 回车换行

帮忙做下100到999最大三位素数,用vb做,谢谢
100到999最大三位素数,用vb做Private Sub Command1_Click()Dim n As Integer, i As Integer, j As Integer, n1 As IntegerDim flag As Booleann1 = 1For n = 900 To 100 Step -1flag = TrueFor i = 2 To Int(Sqr(n))If n Mod i = 0 Thenflag = FalseExit ForEnd IfNextIf ...

vb编程 找出100-900之间的无暇素数。所谓无暇素数是指本身为素数,且其...
Private Sub Command2_Click() For i = 100 To 999 If IsPrime(i) And IsPrime(GetF(i)) Then Print i Next iEnd SubPrivate Function IsPrime(ByVal n As Integer) As Boolean Dim pb As Integer pb = n - 1 IsPrime = True For i = 2 To pb If n Mod ...

产生100个0到999之间的随机整数,然后判断这100个随机整数那些是素数,那 ...
可以用vb编程,编辑一个算法可以求出来

VB语言:要求编写一个函数过程判断某数是否是素数
For i = 100 To 999 flg = sushu(i)If flg = True Then pd = huwen(i)If pd = True Then a = a + 1 Print i;If a Mod 5 = 0 Then Print End If End If Next i End Sub Private Function sushu(n As Integer) As Boolean For i = 2 To n - 1 If n Mod i = 0 ...

利用随机函数产生100-999范围内的一个正整数用vb表达式
Int(900 * Rnd + 100)

...按一个按钮随机出现一道有两个100到999之间的数组成的计算题,如12...
shu1 = Int((999 - 100 + 1) * Rnd + 100)shu2 = Int((999 - 100 + 1) * Rnd + 100)fuhao = Mid("+-×÷", Fix(Rnd() * 4 + 1), 1)Label1.Caption = CStr(shu1) & fuhao & CStr(shu2) & " ="Text1.Text = ""Command2.Enabled = False If Text1.Visible =...

用vb编程实现随机产生一个100到999之间的随机数,并将此数逆序输出_百度...
' 产生20个1-100之间的不重复随机数 Sub RndNumberNoRepeat2()Dim RndNumber, TempArray(99), i As Integer Randomize (Timer) '初始化随机数生成器 For i = 0 To 99 '产生包含1-100的不重复的随机数列 TempArray(i) = i Next i For i = 99 To 80 Step -1 RndNumber = Int(i *...

求数据为三位正整数(即100~999之间),并且它的其各个数字之和等于10 用...
sub tt()dim i for i=100 to 999 if val(left(i,1))+val(right(i,1))+val(mid(i,1,1))=10 then print i next i end sub

相似回答