VB 求10000-99999之间的全部回文式素数我写的程序如下,始终显示ByRef的参数类型错误,Private Function fact(n%) As BooleanDim s%fact = TrueFor s = 2 To n - 1If n Mod i = 0 Thenfact = FalseExit ForEnd IfNext iEnd FunctionPrivate

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/27 18:43:31
VB 求10000-99999之间的全部回文式素数我写的程序如下,始终显示ByRef的参数类型错误,Private Function fact(n%) As BooleanDim s%fact = TrueFor s = 2 To n - 1If n Mod i = 0 Thenfact = FalseExit ForEnd IfNext iEnd FunctionPrivate
xU[OG+H6Ql^* UP*EaMvQhc1v+C&Do^_gffO;8JǮ|=g93cKw^-prnB~=?T:#wk^!+YIhN8?ݖXon~m4ᇬ@Ih*rrFAsb*QBQ4D& ʤsh&2Y( ]E[s]f`yIO tCMeݚ^zC2w(e}.{GBK ~S?( 7_u.78*Y\*~kZ=+Đχba@bǸ ) x'AHrvVl`Jy:%32\SH*CnM o)/3slL?K%K (u'NkM|el./+4>!~DX=ŏ5S;͔")"X/?,lyngv3Bkm[zGx)/:k>}vD{:w?-n~@ ppa%FwΌM,Ug!I-h|qV;Qn1QfV

VB 求10000-99999之间的全部回文式素数我写的程序如下,始终显示ByRef的参数类型错误,Private Function fact(n%) As BooleanDim s%fact = TrueFor s = 2 To n - 1If n Mod i = 0 Thenfact = FalseExit ForEnd IfNext iEnd FunctionPrivate
VB 求10000-99999之间的全部回文式素数
我写的程序如下,始终显示ByRef的参数类型错误,
Private Function fact(n%) As Boolean
Dim s%
fact = True
For s = 2 To n - 1
If n Mod i = 0 Then
fact = False
Exit For
End If
Next i
End Function
Private Function hws(n%) As Boolean
Dim data%,ten%,thu%,wan%
data = n Mod 10
ten = (n \ 10) Mod 10
thu = (n \ 1000) Mod 10
wan = n \ 10000
If data = wan And ten = thu Then
hws = True
End If
End Function
Private Sub Command1_Click()
Dim ,k%
For i = 10000 To 99999
If fact(i) = True And hws(i) = True Then
k = k + 1
Print i;
If k Mod 7 = 0 Then
Print
End If
End If
Next i
End Sub

VB 求10000-99999之间的全部回文式素数我写的程序如下,始终显示ByRef的参数类型错误,Private Function fact(n%) As BooleanDim s%fact = TrueFor s = 2 To n - 1If n Mod i = 0 Thenfact = FalseExit ForEnd IfNext iEnd FunctionPrivate
Private Function fact(n&) As Boolean '错误1:参数n的数据类型应该与command1_click事件里的i类型一致
Dim s& '错误2:s的类型也应该是长整型(&),你原来定义为整形(%)或导致溢出
fact = True
For s = 2 To Sqr(n) '这里循环至sqr(n)即可,可以大大提高代码执行速度,你可以比较一下
If n Mod s = 0 Then '这里i应该改为s,别用i习惯了
fact = False
Exit For
End If
Next s '同样i改成s
End Function
Private Function hws(n&) As Boolean '这里一样n应该定义为长整型,你原来定位为%会导致提示类型不符和溢出
If CStr(n) = StrReverse(CStr(n)) Then hws = True '这里用VB自带的StrReverse函数判断最简单
'StrReverse函数的功能是把字符串前后反转,例如StrReverse("ABCD")为DCBA
End Function
Private Sub Command1_Click()
Dim i&, k% '这里的i你原来定义为单精度型!,建议定义为长整形&,同上上边2个函数的变量n类型应一致
For i = 10000 To 99999
If fact(i) = True And hws(i) = True Then
k = k + 1
Print i;
If k Mod 7 = 0 Then
Print
End If
End If
Next i
End Sub