4个回答
展开全部
'其实挺简单,求素数几乎是初学者的必修课。
'运行效果如上,代码如下所示。
'逐行手敲,亲测可用。
Private Sub Command1_Click()
Dim Inversion As Integer
Dim arr(1000) As Integer
Dim k, a As Integer
k = 1
For i = 1 To 1000
If IsPrimeNumber(i) Then
arr(k) = i '将1000以内的素数放入数组
k = k + 1
End If
Next i
Print "1000内的素数有:"; '把数组打印出来验证效果
For a = 1 To k - 1
Print arr(a);
If a Mod 10 = 0 Then Print
Next a
End Sub
Public Function IsPrimeNumber(ByVal n As Integer) As Boolean
IsPrimeNumber = True
For i = 2 To Sqr(n)
If n Mod i = 0 Then
IsPrimeNumber = False
Exit Function
End If
Next i
End Function
展开全部
1
2
3
4
5
6
7
8
9
10
11
12
Private Sub Command1_Click()
For i = 2 To 1000
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next j
If j = i Then
Print Format(i, "@@@@");
n = n + 1
If n Mod 10 = 0 Then Print
End If
Next i
End Sub
2
3
4
5
6
7
8
9
10
11
12
Private Sub Command1_Click()
For i = 2 To 1000
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next j
If j = i Then
Print Format(i, "@@@@");
n = n + 1
If n Mod 10 = 0 Then Print
End If
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim a() As Integer, i As Integer, j As Integer
ReDim a(0)
a(0)=1
For i = 2 To 1000
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next j
If j = i Then
ReDim Preserve a(UBound(a) + 1)
a(UBound(a)) = i
End If
Next i
ReDim a(0)
a(0)=1
For i = 2 To 1000
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next j
If j = i Then
ReDim Preserve a(UBound(a) + 1)
a(UBound(a)) = i
End If
Next i
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-04-07
展开全部
#include
int main()
{
int a[500];
int n;
int i,j,t;
double ave;
a[0] = 2;
a[1] = 3;
t = 3;
n = 1;
for(i=7;i
int main()
{
int a[500];
int n;
int i,j,t;
double ave;
a[0] = 2;
a[1] = 3;
t = 3;
n = 1;
for(i=7;i
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询