编写一个函数,能判断给定的数据是否为素数.调用该函数,计算区间[100,1000]之间的素数之和.
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/08 06:09:23
编写一个函数,能判断给定的数据是否为素数.调用该函数,计算区间[100,1000]之间的素数之和.
编写一个函数,能判断给定的数据是否为素数.调用该函数,计算区间[100,1000]之间的素数之和.
编写一个函数,能判断给定的数据是否为素数.调用该函数,计算区间[100,1000]之间的素数之和.
Option Explicit Private Sub Command1_Click() Dim i As Long, j As Long Dim s As String For i = 1000 To 9999 s = Trim(Str(i)) If pd(s) Then Text1 = Text1 & s & "=" For j = 1 To Len(s) Text1 = Text1 & Mid(s, j, 1) & "^4" If j < Len(s) Then Text1 = Text1 & "+" Next j Text1 = Text1 & vbCrLf End If Next i End Sub Private Sub Command2_Click() Text1 = "" End Sub Private Sub Command3_Click() Unload Me End Sub Private Function pd(ByVal x As String) As Boolean Dim i As Long Dim m As Long m = 0 For i = 1 To Len(x) m = m + Val(Mid(x, i, 1) ^ 4) Next i If m = Val(x) Then pd = True Else pd = False End If End Function