vb里isprime是什么?
答案:3 悬赏:30
解决时间 2021-02-03 19:25
- 提问者网友:騷女、無惡不作
- 2021-02-02 23:46
vb里isprime是什么?
最佳答案
- 二级知识专家网友:花一样艳美的陌生人
- 2021-02-03 00:38
VB6.0中isprime可能是指判断一个数是否是素数的自定义函数名。
is prime,英文汉译是素数。
Function 语句,声明 Function 过程的名称,参数以及构成其主体的代码。
关于求素数的函数:
Option Explicit
Dim I As Integer
Private Sub Command1_Click()
I = InputBox("i=", I)
Debug.Print IsPrime(I)
End Sub
Private Function IsPrime(ByVal n As Integer) As Boolean
On Error Resume Next
Dim I As Integer
Dim temp As Integer
Dim flag As Boolean
flag = True
If (n <= 1) Then
IsPrime = False
End If
For I = 2 To Sqr(n)
If (n Mod I = 0) Then
flag = False
Exit For
End If
Next I
IsPrime = flag
End Function
is prime,英文汉译是素数。
Function 语句,声明 Function 过程的名称,参数以及构成其主体的代码。
关于求素数的函数:
Option Explicit
Dim I As Integer
Private Sub Command1_Click()
I = InputBox("i=", I)
Debug.Print IsPrime(I)
End Sub
Private Function IsPrime(ByVal n As Integer) As Boolean
On Error Resume Next
Dim I As Integer
Dim temp As Integer
Dim flag As Boolean
flag = True
If (n <= 1) Then
IsPrime = False
End If
For I = 2 To Sqr(n)
If (n Mod I = 0) Then
flag = False
Exit For
End If
Next I
IsPrime = flag
End Function
全部回答
- 1楼网友:不服输就别哭
- 2021-02-03 01:10
思考中!
都是对的,但是结果肯定是0,因为200不是素数,而你在循环中设置了i=0,所以当a=200时,i=0
如果你修改一下,将i=0放到循环之外,就能看到i的大小为3167!
private sub cmd1_click()
dim i as integer, a as integer
i = 0
for a = 100 to 200
if isprime(a) then
i = i + a
next
text1.text = i
end sub
- 2楼网友:請叫我丶偏執狂
- 2021-02-03 00:45
是否是素数.
prime 在数学中就是素数(质数)的意思.
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯