[[練習問題]]

 Sub 係数入力()
 Dim a As Double
 Dim b As Double
 Dim c As Double
 a = Range("A1").Value
 b = Range("B1").Value
 c = Range("C1").Value
 解計算 a, b, c
 End Sub
 Function 解計算(ByVal a As Double, b As Double, c As Double) As Double
 Sub 解計算(ByVal a As Double, b As Double, c As Double)
 Dim d As Double
 Dim x1 As Double
 Dim x2 As Double
 Dim x3 As String
 d = b * b - 4 * a * c
 If d >= 0 Then
   x1 = (-b + Math.Sqr(d)) / (2 * a)
   x2 = (-b - Math.Sqr(d)) / (2 * a)
   x1 = -(b + Math.Sqr(d)) / (2 * a)
   x2 = -(b - Math.Sqr(d)) / (2 * a)
 Else
    x1 = b / (2 * a)
    x2 = Math.Sqr(-d) / (2 * a)
 End If
 x3 = "x1:" & x1 & "、x2:" & x2
 Range("D1").Value = x3
 End Function
 End Sub


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS