第10题怎么做,谢谢,vb里面的
2个回答
展开全部
给个参考的,朋友
Private Sub Form_Click()
Dim a%(), s1%, s%, k%
s1 = InputBox("enter a integer")
s = s1
Do While prime(s)
For i = 2 To s
If s Mod i = 0 And Not prime(i) Then
k = k + 1
ReDim Preserve a(k)
a(k) = i
s = s / i
End If
Next i
Loop
If s <> 1 Then
k = k + 1
ReDim Preserve a(k)
a(k) = s
End If
For i = 1 To k
For j = 1 To k - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
Print s1 & "=";
For i = 1 To k
If i <> k Then
Print a(i); "*";
Else
Print a(i)
End If
Next
End Sub
Private Function prime(ByVal x%) As Boolean
For i = 2 To Sqr(x)
If x Mod i = 0 Then
prime = True
Exit For
End If
Next
End Function
Private Sub Form_Click()
Dim a%(), s1%, s%, k%
s1 = InputBox("enter a integer")
s = s1
Do While prime(s)
For i = 2 To s
If s Mod i = 0 And Not prime(i) Then
k = k + 1
ReDim Preserve a(k)
a(k) = i
s = s / i
End If
Next i
Loop
If s <> 1 Then
k = k + 1
ReDim Preserve a(k)
a(k) = s
End If
For i = 1 To k
For j = 1 To k - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
Print s1 & "=";
For i = 1 To k
If i <> k Then
Print a(i); "*";
Else
Print a(i)
End If
Next
End Sub
Private Function prime(ByVal x%) As Boolean
For i = 2 To Sqr(x)
If x Mod i = 0 Then
prime = True
Exit For
End If
Next
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询