Квадратное уравнение в Basic
Пример для версий
VB.NET 9 (2008),
vbnc 2.4.2
Module Module1
Sub Main()
Dim A, B, C, D As Integer
Dim p1, p2 As Double
Try
Console.Write("A = ")
A = Val(Console.ReadLine())
Console.Write("B = ")
B = Val(Console.ReadLine())
Console.Write("C = ")
C = Val(Console.ReadLine())
Catch ex As Exception
Console.WriteLine("Invalid input.")
Return
End Try
If A = 0 Then
Console.WriteLine("Not a quadratic equation.")
Return
End If
D = B * B - 4 * A * C
p1 = -B / 2.0 / A
p2 = Math.Sqrt(Math.Abs(D)) / 2.0 / A
If D = 0 Then
Console.Write("x = " & p1.ToString())
ElseIf D > 0 Then
Console.WriteLine("x1 = " & (p1 + p2).ToString())
Console.WriteLine("x2 = " & (p1 - p2).ToString())
Else
Console.WriteLine("x1 = (" & p1.ToString() & "," & p2.ToString() & ")")
Console.WriteLine("x2 = (" & p1.ToString() & ",-" & p2.ToString() & ")")
End If
End Sub
End Module
Комментарии
]]>blog comments powered by Disqus
]]>