- 追加された行はこの色です。
- 削除された行はこの色です。
[[練習問題]]
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 解計算(a, b, c)
Dim d As Double
Dim x1 As Double
Dim x2 As Double
Dim x3 As String
Dim x4 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)
x3 = x1
x4 = x2
Else
x1 = b / (2 * a)
x2 = Sqr(-d) / (2 * a)
x3 = x1 & "±" & x2
x4 = 0
End If
表示 x3, x4
End Function
Function 表示(x3, x4)
Range("D1").Value = x3
Range("D2").Value = x4
End Function