輸入應該是1,-2,1吧? 不然輸出應該是 -0.5 1 Private Sub Form_Load() Me.Hide Dim a, b, c As Single Dim ans, ans1 As Integer Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Line Input #1, x x = Replace(x, ",", " ") y = Split(x, " ") a = Val(y(0)) b = Val(y(1)) c = Val(y(2)) d = (b ^ 2 - ((4 * a) * c)) ^ 0.5 If d > 0 Then ans = (-(b) + d) / (a * 2) ans1 = (-(b) - d) / (a * 2) Print #2, ans & " " & ans1 ElseIf d = 0 Then ans = (-(b) + d) / (a * 2) Print #2, ans Else Print #2, "I can’t solve it !" End If Close Close End End Sub
輸入應該是1,-2,1吧?
回覆刪除不然輸出應該是 -0.5 1
Private Sub Form_Load()
Me.Hide
Dim a, b, c As Single
Dim ans, ans1 As Integer
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Line Input #1, x
x = Replace(x, ",", " ")
y = Split(x, " ")
a = Val(y(0))
b = Val(y(1))
c = Val(y(2))
d = (b ^ 2 - ((4 * a) * c)) ^ 0.5
If d > 0 Then
ans = (-(b) + d) / (a * 2)
ans1 = (-(b) - d) / (a * 2)
Print #2, ans & " " & ans1
ElseIf d = 0 Then
ans = (-(b) + d) / (a * 2)
Print #2, ans
Else
Print #2, "I can’t solve it !"
End If
Close
Close
End
End Sub
恩 我也有這個疑問
刪除不過問題是別人給我的
那就以 -0.5 跟 1 為答案吧