eqn_2eme_deg.c
00001 #include <stdio.h>
00002 #include <math.h>
00003
00004 void solve_eqn_1er_deg(float a, float b);
00005
00006 void solve_eqn_2eme_deg(float a, float b, float c) {
00007 if (a == 0) solve_eqn_1er_deg(b,c);
00008 else {
00009 float delta = b*b - 4*a*c;
00010 if (delta < 0) printf("S = ensemble vide (aucune solution)\n");
00011 else if (delta == 0) printf("S = {%f} (une solution souble)\n",-b/(2*a));
00012 else
00013 printf("S = {%f, %f} (deux solutions)\n",
00014 (-b - sqrt(delta))/(2*a), (-b + sqrt(delta))/(2*a));
00015 }
00016 }
00017 int main()
00018 {
00019 float a, b, c;
00020 printf("*** Résolution automatique de l'équation (en x) a.x^2+b.x+c = 0 ***\n");
00021 printf("a = "); scanf("%f", &a);
00022 printf("b = "); scanf("%f", &b);
00023 printf("c = "); scanf("%f", &c);
00024 printf("-> résolution de %fx^2 + %f.x + %f = 0\n",a,b,c);
00025 solve_eqn_2eme_deg(a,b,c);
00026 return 0;
00027 }
00028
00029
00030 void solve_eqn_1er_deg(float a, float b) {
00031 if (a == 0) {
00032 if (b == 0) printf("S = R (tout réel x est solution)\n");
00033 else printf("S = ensemble vide (aucune solution réelle)\n");
00034 } else {
00035 printf("S = {%f} (une unique solution)\n",-b/a);
00036 }
00037 }