Présentation de l'algorithme :
Résolution de l'équation du second degré à coefficients réels.
Tester l'algorithme :
Graphique :
Code de l'algorithme :
1    
 VARIABLES
2      
 a EST_DU_TYPE NOMBRE
3      
 b EST_DU_TYPE NOMBRE
4      
 c EST_DU_TYPE NOMBRE
5      
 DELTA EST_DU_TYPE NOMBRE
6      
 RAC EST_DU_TYPE NOMBRE
7      
 RAC2 EST_DU_TYPE NOMBRE
8      
 RE_SOL EST_DU_TYPE NOMBRE
9      
 IM_SOL EST_DU_TYPE NOMBRE
10     
 ABS_b EST_DU_TYPE NOMBRE
11     
 ABS_c EST_DU_TYPE NOMBRE
12   
 DEBUT_ALGORITHME
13     
 //Saisie des coefficients a, b et c.
14     
 AFFICHER "Saisissez les coefficients a, b et c (Rappel : a doit être non nul !)"
15     
 //Première saisie du coefficient a
16     
 LIRE a
17     
 TANT_QUE (a==0) FAIRE
18       
 DEBUT_TANT_QUE
19       
 AFFICHER "ATTENTION ! Le coefficient a doit être non nul !"
20       
 LIRE a
21       
 FIN_TANT_QUE
22     
 //Le coefficient a saisi est non nul.
23     
 AFFICHER "a = "
24     
 AFFICHER a
25     
 LIRE b
26     
 AFFICHER "b = "
27     
 AFFICHER b
28     
 LIRE c
29     
 AFFICHER "c = "
30     
 AFFICHER c
31     
 //Affichage "naturel" de l'équation à résoudre.
32     
 AFFICHER "Résolution de l'équation "
33     
 SI (a!=1) ALORS
34       
 DEBUT_SI
35       
 SI (a==-1) ALORS
36         
 DEBUT_SI
37         
 AFFICHER "-"
38         
 FIN_SI
39         
 SINON
40           
 DEBUT_SINON
41           
 AFFICHER a
42           
 FIN_SINON
43       
 FIN_SI
44     
 AFFICHER "x²"
45     
 SI (b!=0) ALORS
46       
 DEBUT_SI
47       
 SI (b==1) ALORS
48         
 DEBUT_SI
49         
 AFFICHER "+x"
50         
 FIN_SI
51         
 SINON
52           
 DEBUT_SINON
53           
 SI (b==-1) ALORS
54             
 DEBUT_SI
55             
 AFFICHER "-x"
56             
 FIN_SI
57             
 SINON
58               
 DEBUT_SINON
59               
 ABS_b PREND_LA_VALEUR abs(b)
60               
 SI (b<0) ALORS
61                 
 DEBUT_SI
62                 
 AFFICHER "-"
63                 
 FIN_SI
64                 
 SINON
65                   
 DEBUT_SINON
66                   
 AFFICHER "+"
67                   
 FIN_SINON
68               
 AFFICHER ABS_b
69               
 AFFICHER "x"
70               
 FIN_SINON
71           
 FIN_SINON
72       
 FIN_SI
73     
 SI (c!=0) ALORS
74       
 DEBUT_SI
75       
 ABS_c PREND_LA_VALEUR abs(c)
76       
 SI (c<0) ALORS
77         
 DEBUT_SI
78         
 AFFICHER "-"
79         
 FIN_SI
80         
 SINON
81           
 DEBUT_SINON
82           
 AFFICHER "+"
83           
 FIN_SINON
84       
 AFFICHER ABS_c
85       
 FIN_SI
86     
 AFFICHER " = 0"
87     
 //Calcul du discriminant associé à l'équation
88     
 DELTA PREND_LA_VALEUR pow(b,2)-4*a*c
89     
 AFFICHER "Le discriminant Delta associé à votre équation vaut "
90     
 AFFICHER DELTA
91     
 //Résolution de l'équation suivant le signe de Delta.
92     
 SI (DELTA<0) ALORS
93       
 DEBUT_SI
94       
 //Cas où le discriminant est strictement négatif.
95       
 //Calcul des deux racines complexes conjuguées.
96       
 RE_SOL PREND_LA_VALEUR -b/(2*a)
97       
 IM_SOL PREND_LA_VALEUR sqrt(-DELTA)/(2*a)
98       
 AFFICHER "Votre équation n'admet pas de solution réelle."
99       
 AFFICHER "L'équations admet deux racines complexes conjuguées : "
100      
 SI (RE_SOL==0) ALORS
101        
 DEBUT_SI
102        
 SI (IM_SOL!=1) ALORS
103          
 DEBUT_SI
104          
 AFFICHER IM_SOL
105          
 FIN_SI
106        
 AFFICHER "i"
107        
 FIN_SI
108        
 SINON
109          
 DEBUT_SINON
110          
 AFFICHER RE_SOL
111          
 AFFICHER "+"
112          
 AFFICHER IM_SOL
113          
 AFFICHER "i"
114          
 FIN_SINON
115      
 AFFICHER " et "
116      
 SI (RE_SOL==0) ALORS
117        
 DEBUT_SI
118        
 AFFICHER "-"
119        
 SI (IM_SOL!=1) ALORS
120          
 DEBUT_SI
121          
 AFFICHER IM_SOL
122          
 FIN_SI
123        
 AFFICHER "i"
124        
 FIN_SI
125        
 SINON
126          
 DEBUT_SINON
127          
 AFFICHER RE_SOL
128          
 AFFICHER "-"
129          
 AFFICHER IM_SOL
130          
 AFFICHER "i"
131          
 FIN_SINON
132      
 FIN_SI
133      
 SINON
134        
 DEBUT_SINON
135        
 SI (DELTA==0) ALORS
136          
 DEBUT_SI
137          
 //Cas où le discriminant est nul.
138          
 RAC PREND_LA_VALEUR -b/(2*a)
139          
 AFFICHER "Votre équation admet pour unique solution : "
140          
 AFFICHER RAC
141          
 FIN_SI
142          
 SINON
143            
 DEBUT_SINON
144            
 //Cas où le discriminant est strictement positif.
145            
 RAC PREND_LA_VALEUR (-b-sqrt(DELTA))/(2*a)
146            
 RAC2 PREND_LA_VALEUR (-b+sqrt(DELTA))/(2*a)
147            
 AFFICHER "Votre équation admet deux solutions réelles : "
148            
 AFFICHER RAC
149            
 AFFICHER " et "
150            
 AFFICHER RAC2
151            
 FIN_SINON
152        
 FIN_SINON
153  
 FIN_ALGORITHME