求100到999之间最大三个素数的C语言程序

2025-01-04 00:55:06
推荐回答(2个)
回答1:

#include//欧几里得算法 素质表
#define N 999
int main()
{
long int isPrime[N];
int m, i, j;
int cnt = -1;
for (i = 0; i isPrime[i] = 1;
}
for (m = 2; m
if (isPrime[m]) {
cnt++;

for (j = m; m*j isPrime[j*m] = 0;
}
isPrime[cnt] = m;
}
}
for (i = 0; i <= cnt; i++) {
printf("%d\t\t", isPrime[i]);
}
return 0;
}
欧几里得算法,这能找出2~N之间多有质数,并按顺序打印出来。

回答2:

Private Sub Command1_Click()
Dim n As Integer, i As Integer, j As Integer, n1 As Integer
Dim flag As Boolean
n1 = 1
For n = 900 To 100 Step -1
flag = True
For i = 2 To Int(Sqr(n))
If n Mod i = 0 Then
flag = False
Exit For
End If
Next
If flag Then
Do While n1 <= 3
Print n;

n1 = n1 + 1
Exit Do
Loop

End If

Next

End Sub