請問c++
1-100的質數要全部印出~~
要怎麼寫阿= =?
謝謝...
2006-11-27 15:23:47 · 2 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
#include
2006-11-27 15:27:18 · answer #1 · answered by flymouse.tw 7 · 0⤊ 0⤋
Visual Basic 的寫法 參考一下
Private Sub Form_Activate()
n = Val(InputBox("", "", "32767"))
If n = 2 Then
Sum = 2: Max = 2: C = 1
ElseIf n <= 4 Then
Sum = 5: Max = 3: C = 2
ElseIf n > 4 Then
For I = 5 To n
CHK = True
For J = 2 To Sqr(I)
If I Mod J = 0 Then
CHK = False
Exit For
End If
Next J
If CHK = True Then
Max = I
Sum = Sum + I
C = C + 1
End If
Next I
End If
Print "所有質數加總:" & Sum
Print "個數:"; C
Print "最接近N的質數:" & Max
End Sub
'條件N>4 和 N < 1000 請自己寫
2006-11-28 06:05:16 · answer #2 · answered by ? 1 · 0⤊ 0⤋