发布网友 发布时间:2023-11-09 10:10
共1个回答
热心网友 时间:2024-08-06 09:21
Private Sub Command1_Click()
Dim I As Integer, J As Integer
Dim A As Integer, B As Integer
Dim S As String, N As Integer
Dim P As String
A = Val(Text1.Text)
B = Val(Text2.Text)
For I = A To B
P = ""
If Prime(Sum(I ^ 2)) = True Then
S = CStr(I ^ 2)
For J = 1 To Len(S) - 1
P = P & Mid(S, J, 1) & "+"
Next
P = P & Right(S, 1) & "=" & Sum(I ^ 2)
List1.AddItem CStr(I) & "^2=" & I ^ 2 & ":" & P
End If
Next
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
List1.Clear
Text1.SetFocus
End Sub
Function Sum(N As Integer) As Integer '求一个整数各位数之和
Dim I As Integer, S As String
S = CStr(N)
For I = 1 To Len(S)
Sum = Sum + Val(Mid(S, I, 1))
Next
End Function
Function Prime(N As Integer) As Boolean '判断一个整数是否为素数
Dim I As Integer
If N <= 1 Then Prime = False: Exit Function
For I = 2 To N / 2
If N Mod I = 0 Then
Prime = False
Exit Function
End If
Next
If I > N / 2 Then Prime = True
End Function
Private Sub Form_Load()
Form1.Caption = "看不清楚标题,这儿自己改"
End Sub