I wrote an application with VisualBasic 2008 to solve quadratic formulas.
The most important part is this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
x3 = ((b ^ 2) - (4 * a * c))
If x3 < 0 Then
TextBox4.Text = "D < 0"
TextBox5.Text = "D < 0"
MessageBox.Show("D<0", "Fehler", MessageBoxButtons.OK)
Else
x1 = (-b - Math.Sqrt((b ^ 2) - (4 * a * c))) / (2 * a)
x2 = (-b + Math.Sqrt((b ^ 2) - (4 * a * c))) / (2 * a)
TextBox4.Text = x1
TextBox5.Text = x2
End If
End Sub
Here, x1 and x2 is calculated and checked whether the discriminant is smaller than zero. In VB you use Math.Sqrt ( ) to extract a root.
You can download this application here:
http://christianlachmann.de.vu/QuadratischeGleichung.exe
But it's in German language.
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment