]]> ]]>

Квадратное уравнение в Basic

Пример для версий VBA 6.3, VBA 6.5
Function GetInt(Name As String) As Integer
  Dim Coef As String
  Coef = Application.InputBox("Enter Coefficient " & Name)
  GetInt = CInt(Coef)
End Function

Sub Quadratic()
  Dim A As Integer, B As Integer, C As Integer, D As Integer
  A = GetInt("A")
  If A = 0 Then
    MsgBox ("Not a quadratic equation.")
    Exit Sub
  End If
  B = GetInt("B")
  C = GetInt("C")
  D = B * B - 4 * A * C
  Dim p1 As Double, p2 As Double
  p1 = -B / 2# / A
  p2 = Sqr(Abs(D)) / 2# / A
  If D = 0 Then
    MsgBox ("x = " & CStr(p1))
  Else
    If D > 0 Then
      MsgBox ("x1 = " & CStr(p1 + p2) & Chr(10) & "x2 = " & CStr(p1 - p2))
    Else
      MsgBox ("x1 = (" & CStr(p1) & ", " & CStr(p2) & ")" & Chr(10) & "x2 = (" & CStr(p1) & ", " & CStr(-p2) & ")")
    End If
  End If
End Sub

Комментарии

]]>

blog comments powered by Disqus

]]>

Работа программистам