用VB编写程序,输入一个正整数n,求所有大于1且小于n,同时与n互质的数,存入一个数组并每行5个的格式输出

谢谢啦 我这种完全不会呀

同时与n互质的数 ------这个不太明白?能说一下吗? 下面1000以内质数算法。
Private Sub Command1_Click()
Text1.Text = ""
For i = 1 To 1000
k = 1
For j = 2 To i / 2
If i Mod j = 0 Then k = 0
Next j
If k = 1 Then
'Print i
Text1.Text = Text1.Text & i & " "
End If
Next i
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-03
Option Explicit
Dim S() As Long

Function HZS(ByVal n As Long)
ReDim S(n) As Long
Dim Tmp1 As Long, Tmp2 As Long, Tmp3 As Long
Dim BL As Boolean
For Tmp1 = 2 To n
BL = True
For Tmp2 = 2 To Tmp1
If Tmp1 Mod Tmp2 = 0 And n Mod Tmp2 = 0 Then
BL = False
Exit For
End If
Next
If BL Then
Tmp3 = Tmp3 + 1
S(Tmp3) = Tmp1
End If
Next

'输出
For Tmp1 = 1 To Tmp3
Print S(Tmp1),
If Tmp1 Mod 5 = 0 Then Print
Next
End Function
相似回答