1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Option Explicit
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim delta As Integer
Dim x As Integer
Dim x1 As Integer
Dim x2 As Integer
'Déclaration des variables
Private Sub Command1_Click()
'Algorithme qui résout une équation du second degré
a = InputBox("A=", "**SAISIE**")
b = InputBox("B=", "**SAISIE**")
c = InputBox("C=", "**SAISIE**")
If a = 0 And b = 0 And c = 0 Then
MsgBox ("Tout est solution")
ElseIf a = 0 And b = 0 And c <> 0 Then
MsgBox ("Impossible de résoudre cette équation")
ElseIf a <> 0 Then
delta = (b * b) - 4 * a * c
End If
If delta < 0 Then
MsgBox ("Pas de solution")
ElseIf delta = 0 Then
x = (-b) / (2 * a)
MsgBox ("Il existe une unique solution qui est " & x)
Else: x1 = ((-b) - (delta ^ (1 / 2))) / (2 * a)
x2 = ((-b) + (delta ^ (1 / 2))) / (2 * a)
MsgBox ("Il existe deux solutions qui sont " & x1 & " et " & x2)
End If
End Sub |
Partager