求1000以内所有素数的算法与vB程序语言对应

2024-11-30 23:34:30
推荐回答(2个)
回答(1):

你自己用vb改改吧
int sushu(){
int i=0,n;
bool isFind;
for(i=2;i<1000;i++){
isFind=true;
for(n=2;n<1000;n++){
if(i!=n && i % n ==0){
isFind=false;
break;
}
}
if(isFind)
qDebug()< }
return 0;
}

回答(2):

Dim i As Integer
Dim j As Integer
Dim s As String
For i = 2 To 1000
For j = 2 To Int(i / 2)
If i Mod j = 0 Then
Exit For
End If
Next j
If j = Int(i / 2) + 1 Then
s = s & Str(i) & ","
End If
Next i