Private Sub Form_Load() Me.Hide Dim n As Boolean n = True Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x
For i = 2 To (x - 1) If x Mod i = 0 Then n = False Next
If n = False Then Print #2, "不是質數" Else Print #2, "是質數" End If
Private Sub Form_Load() Dim n As Boolean Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x n = True For i = 2 To (x - 1) If x Mod i = 0 Then n = False Next i
If n = False Then Print #2, "不是質數" Else Print #2, "是質數" End If
Private Sub Form_Load() Dim n As Boolean Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x n = False For i = 2 To (x - 1) If x Mod i = 0 Then n = True Next i
If (x >= 2) And (n = False) Then Print #2, "是質數" Else Print #2, "不是質數" End If
Private Sub Form_Load() Me.Hide Dim n As Boolean n = True Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x
For i = 2 To (x - 1) If x Mod i = 0 Then n = False Next
If x <= 1 Then n = False
If n = False Then Print #2, "不是質數" Else Print #2, "是質數" End If
Private Sub Form_Load() Dim n As Boolean n = True Open App.Path & "/in.txt " For Input As 1 Open App.Path & "/out.txt" For Output As 2 Input #1, x For i = 2 To (x - 1) If x Mod i = 0 Then n = False Next If x = 0 Or 1 Then n = False If n = True Then Print #2, x, "是質數" Else Print #2, x, "不是質數" End If Close Close End End Sub
Private Sub Form_Load() Dim n As Boolean n = True Open App.Path & "/in.txt " For Input As 1 Open App.Path & "/out.txt" For Output As 2 Input #1, x For i = 2 To (x - 1) If x Mod i = 0 Then n = False Next If x < 2 Then n = False If n = False Then Print #2, x, "不是質數" Else Print #2, x, "是質數" End If Close Close End End Sub
Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Dim n As Boolean n = True Input #1, s For i = 2 To (s - 1) If s Mod i Then n = False Next If (s <= 2) And (n = False) Then Print #2, "不是質數" Else Print #2, "是質數" End If Close Close End End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim n As Boolean
n = True
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x
For i = 2 To (x - 1)
If x Mod i = 0 Then n = False
Next
If n = False Then
Print #2, "不是質數"
Else
Print #2, "是質數"
End If
Close
Close
End
End Sub
Private Sub Form_Load()
回覆刪除Dim n As Boolean
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
n = True
For i = 2 To (x - 1)
If x Mod i = 0 Then n = False
Next i
If n = False Then
Print #2, "不是質數"
Else
Print #2, "是質數"
End If
Close #2
Close #1
End
End Sub
兩個程式有錯
回覆刪除如果輸入0或1呢?
自己上網查一下吧
Private Sub Form_Load()
回覆刪除Dim n As Boolean
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
n = False
For i = 2 To (x - 1)
If x Mod i = 0 Then n = True
Next i
If (x >= 2) And (n = False) Then
Print #2, "是質數"
Else
Print #2, "不是質數"
End If
Close #2
Close #1
End
End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim n As Boolean
n = True
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x
For i = 2 To (x - 1)
If x Mod i = 0 Then n = False
Next
If x <= 1 Then n = False
If n = False Then
Print #2, "不是質數"
Else
Print #2, "是質數"
End If
Close
Close
End
End Sub
Private Sub Form_Load()
回覆刪除Dim n As Boolean
n = True
Open App.Path & "/in.txt " For Input As 1
Open App.Path & "/out.txt" For Output As 2
Input #1, x
For i = 2 To (x - 1)
If x Mod i = 0 Then n = False
Next
If x = 0 Or 1 Then n = False
If n = True Then
Print #2, x, "是質數"
Else
Print #2, x, "不是質數"
End If
Close
Close
End
End Sub
小冰、晟晟程式對了,這種小細節要多注意。
回覆刪除哲哲程式有錯噢:
要注意看輸出範例的輸出 (這個很嚴重噢
還有你t/f顛倒了
Private Sub Form_Load()
回覆刪除Dim n As Boolean
n = True
Open App.Path & "/in.txt " For Input As 1
Open App.Path & "/out.txt" For Output As 2
Input #1, x
For i = 2 To (x - 1)
If x Mod i = 0 Then n = False
Next
If x < 2 Then n = False
If n = False Then
Print #2, x, "不是質數"
Else
Print #2, x, "是質數"
End If
Close
Close
End
End Sub
改好了:D
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Dim n As Boolean
n = True
Input #1, s
For i = 2 To (s - 1)
If s Mod i Then n = False
Next
If (s <= 2) And (n = False) Then
Print #2, "不是質數"
Else
Print #2, "是質數"
End If
Close
Close
End
End Sub