今天做了 解一元二次方程式

需要 button*2 textbox*4 label*3

程式碼 如下



Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b, c, check As Integer
Dim ans1, ans2 As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
c = Val(TextBox3.Text)
check = b * b - 4 * a * c
If check = 0 Then
ans1 = -b / (2 * a)
txtOutput.Text = "有兩個等根:" & ans1
ElseIf check < 0 Then
txtOutput.Text = "有兩個虛根"
Else
ans1 = (-b + Math.Sqrt(check)) / (2 * a)
ans2 = (-b - Math.Sqrt(check)) / (2 * a)
txtOutput.Text = "有兩個相異的實根:" & ans1 & "," & ans2
End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class

部分可自行修改

完成後下圖


創作者介紹

↖Ι n V a D e R ╮

ip612256374 發表在 痞客邦 PIXNET 留言(1) 人氣()


留言列表 (1)

發表留言