Quadratic equation in Basic
Example for versions
VBScript 5.7,
VBScript 5.8
Function GetInt()
Input = WScript.StdIn.ReadLine
If not IsNumeric(Input) Then
WScript.Echo "Coefficient is not a number."
WScript.Quit
End If
GetInt = CInt(Input)
End Function
A = GetInt()
If A = 0 Then
WScript.Echo "Not a quadratic equation."
WScript.Quit
End If
B = GetInt()
C = GetInt()
D = B * B - 4 * A * C
p1 = -B / 2.0 / A
p2 = Sqr(Abs(D)) / 2.0 / A
If D = 0 Then
WScript.Echo "x = " & p1
Else
If D > 0 Then
WScript.Echo "x1 = " & (p1 + p2)
WScript.Echo "x2 = " & (p1 - p2)
Else
WScript.Echo "x1 = (" & p1 & ", " & p2 & ")"
WScript.Echo "x2 = (" & p1 & ", " & -p2 & ")"
End If
End If
Comments
]]>blog comments powered by Disqus
]]>