求1到300之间的素数?
答案:1 悬赏:10 手机版
解决时间 2021-11-24 06:52
- 提问者网友:缘字诀
- 2021-11-23 23:55
求1到300之间的素数?
最佳答案
- 五星知识达人网友:拜訪者
- 2021-11-24 00:55
Dim n As Integer, sum As Integer, j As Integer
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "所求的素数为:" & vbCrLf
For i = 2 To 300
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next j
If j > i - 1 Then
n = n + 1
sum = sum + i
TextBox1.Text = TextBox1.Text & i & " "
If n Mod 10 = 0 Then TextBox1.Text = TextBox1.Text & vbCrLf
End If
Next i
TextBox1.Text = TextBox1.Text & vbCrLf
TextBox1.Text = TextBox1.Text & "共有" & n & "个素数,它们的和为" & sum & vbCrLf
TextBox1.Text = ""
TextBox1.Text = TextBox1.Text & "所求的素数为:" & vbCrLf
For i = 2 To 300
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next j
If j > i - 1 Then
n = n + 1
sum = sum + i
TextBox1.Text = TextBox1.Text & i & " "
If n Mod 10 = 0 Then TextBox1.Text = TextBox1.Text & vbCrLf
End If
Next i
TextBox1.Text = TextBox1.Text & vbCrLf
TextBox1.Text = TextBox1.Text & "共有" & n & "个素数,它们的和为" & sum & vbCrLf
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯