Sub Main() Dim Real_1 As Double = 0 Dim Real_2 As Double = 0 Dim Imag As Double = 0 Dim Flag As String Dim A As Double = 0 Dim B As Double = 0 Dim C As Double = 0 Dim D As Double = 0 Dim DD As Double = 0 Console.WriteLine("This program computes both roots of a quadratic equation given A, B anc C") Console.ReadLine() Do Console.WriteLine("Do you want to run the program?") Flag = Console.ReadLine() If Flag = "Y" Then Console.WriteLine("Enter A") A = Console.ReadLine Console.WriteLine("Enter B") B = Console.ReadLine() Console.WriteLine("Enter C") C = Console.ReadLine() D = (B ^ 2 - 4 * A * C) If D < 0 Then DD = (4 * A * C - B ^ 2) ^ (0.5) Imag = DD / (2 * A) Real_1 = -B / (2 * A) Real_2 = -B / (2 * A) End If If D = 0 Then Imag = 0 Real_1 = -B / (2 * A) Real_2 = -B / (2 * A) End If If D > 0 Then Imag = 0 Real_1 = (-B + D ^ (0.5)) / (2 * A) Real_2 = (-B - D ^ (0.5)) / (2 * A) End If Console.WriteLine("Solution 1 is = " & Real_1 & ("") & "+J" & Imag) Console.ReadLine() Console.WriteLine("Solution 2 is = " & Real_2 & ("") & "-J" & Imag) Console.ReadLine() Else Environment.Exit(0) End If Loop End Sub End Module
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)