我有這個可視化的基本代碼來接收用戶輸入並打印出許多素數。例如,如果用戶輸入5,輸出應該是:1,3,5,7,11,但我發現it.Here困難是我的代碼:如何在Visual Basic(表單)中打印N個素數?
Dim i, n, input, currentPrime As Integer
Dim Wrap As String = Chr(10) & Chr(13)
input = txtInput.Text
currentPrime = 1
txtAns.Text = "Prime Numbers are : " & Wrap
Do While (currentPrime <= input)
For i = currentPrime To input
For j = 2 To Fix(i/2) + 1
If i Mod j = 0 Then
n = 1
End If
Next
If n = 1 Then
n = 0
Else
txtAns.Text = txtAns.Text & Wrap & i & " is a prime number " & Wrap
End If
Next
currentPrime += 1
Loop
我有關於我的代碼的問題。我發現它很困難。我的輸出應該是如果用戶輸入5,輸出應該是:1,3,5,7,11。但我的是直到499 :( – 2014-12-13 02:24:00
可能重複[如何在Vb.net中打印N個素數(形式)?](http://stackoverflow.com/questions/27446434/how-to-print-n-number-of-primes-in-vb-net-forms) – AJDev 2014-12-13 02:57:41
我該如何開始我的序列2? – 2014-12-13 06:12:24