'6.輸入 A, B, C,求 AX^2 + BX + C = 0 的解。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'測試資料
'Dim a = 4
'Dim b = -5
'Dim c = 1
'輸入資料
Dim a = InputBox("a=")
Dim b = InputBox("b=")
Dim c = InputBox("c=")
If b ^ 2 - 4 * a * c < 0 Then
MsgBox("無實數解")
Else
Dim x1 = (-b + (b ^ 2 - 4 * a * c) ^ 0.5) / (2 * a)
Dim x2 = (-b - (b ^ 2 - 4 * a * c) ^ 0.5) / (2 * a)
MsgBox("解為:" & x1 & "," & x2)
End If
End Sub
End Class
沒有留言:
張貼留言