vb.net - Quadratic equation with complex roots -
i learning visual basic , have been trying write code solve quadratic equations complex number roots. pointer in right direction appreciated.
public class form1 dim a, b, c integer dim x1, x2 double private sub label4_click(sender object, e eventargs) handles label4.click end sub private sub textbox4_textchanged(sender object, e eventargs) handles eqnrt1.textchanged end sub private sub button3_click(sender object, e eventargs) handles btnexit.click close() end sub private sub btnclear_click(sender object, e eventargs) handles btnclear.click txta.text = "" txtb.text = "" txtc.text = "" eqnrt1.text = "" eqnrt2.text = "" end sub private sub btncalc_click(sender object, e eventargs) handles btncalc.click dim a,b,c integer = txta.text b = txtb.text c = txtc.text dim x1 = (-b + math.sqrt(b * b - 4 * * c)) / (2 * a) dim x2 = (-b - math.sqrt(b * b - 4 * * c)) / (2 * a) eqnrt1.text = str(x1) eqnrt2.text = str(x2) end sub private sub form1_load(sender object, e eventargs) handles mybase.load end sub end class
there quite few answers on internet ...
sub main() dim a, b, c single console.writeline("write coefficient 'a'") = console.readline console.writeline("write coefficient 'b'") b = console.readline console.writeline("write coefficient 'c'") c = console.readline dim d integer = b ^ 2 - 4 * * c if d >= 0 if d = 0 console.writeline("roots real , equal") else console.writeline("roots real , different") end if console.write("roots are: ") console.write((-b + d ^ 0.5) / (2 * a) & " , ") console.writeline((-b - d ^ 0.5) / (2 * a)) else console.writeline("roots complex") console.write("roots are: ") console.write(-b / (2 * a) & "+" & (d * -1) ^ 0.5 / (2 * a) & "i") console.write(" , ") console.writeline(-b / (2 * a) & "-" & (d * -1) ^ 0.5 / (2 * a) & "i") end if console.readline() end sub
Comments
Post a Comment