vb编写程序找出3~100间所有素数并输出窗体
3个回答
2014-11-06 · 知道合伙人软件行家
yfcp
知道合伙人软件行家
向TA提问 私信TA
知道合伙人软件行家
采纳数:1748
获赞数:5545
有多年网站建设相关工作经验。熟悉ASP、ASP.net、VB、JavaScript、HTML等语言和CSS、Ajax等相关技术。
向TA提问 私信TA
关注
展开全部
Private Sub Command1_Click()
Dim s As Long, x As Long
For s = 3 To 100
If zhi(s) Then x = x + 1: Print s
Next
Print "共 " & x & "个质数"
End Sub
Private Function zhi(x As Long) As Boolean
Dim b As Single, i As Long, f As Long
For i = 2 To x - 1
If x Mod i = 0 Then
f = 1: Exit For
End If
Next
If f = 1 Then zhi = False Else zhi = True
End Function
展开全部
Private Sub form_click()
Dim N As Integer
Dim I As Integer
Dim J As Integer
Dim S As Boolean
N = 0
For I = 3 To 100
S = True
For J = 2 To Sqr(I)
If I Mod J = 0 Then
S = False
Exit For
End If
Next
If S Then
Print Format(I, " 0# ");
N = N + 1
If N Mod 10 = 0 Then Print
End If
Next
Print
Print "从3-100之间共有以上"; N; "个素数"
End Sub
Dim N As Integer
Dim I As Integer
Dim J As Integer
Dim S As Boolean
N = 0
For I = 3 To 100
S = True
For J = 2 To Sqr(I)
If I Mod J = 0 Then
S = False
Exit For
End If
Next
If S Then
Print Format(I, " 0# ");
N = N + 1
If N Mod 10 = 0 Then Print
End If
Next
Print "从3-100之间共有以上"; N; "个素数"
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
For i = 3 To 100
For j = 2 To Sqr(i)
If i Mod j = 0 Then Exit For
Next j
If i Mod j <> 0 Then
Print i,
k = k + 1
If k Mod 5 = 0 Then Print
End If
Next i
End Sub
For i = 3 To 100
For j = 2 To Sqr(i)
If i Mod j = 0 Then Exit For
Next j
If i Mod j <> 0 Then
Print i,
k = k + 1
If k Mod 5 = 0 Then Print
End If
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询