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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| /* ceci est le TP2 */
/* */
/*resolution equation diff du 2nd ordre*/
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
/*déclaration des variables locales*/
float a,b,c,sol1,sol2,det;
/*float sol1,sol2,det;*/
int existsol1,existsol2;
/*char chaine[20];*/
/* saisie des coeff*/
printf("entrez a \n");
scanf("%f",&a);
printf("entrez b \n");
scanf("%f",&b);
printf("entrez c \n");
scanf("%f",&c);
/*printf("%.2f x²+ %.2f x+ %.2f = 0 \n",a,b,c);
det=sqrt((pow(b,b))-4*a*c);
printf("det= %f\n",det);*/
/* printf("%.2f x²+ %.2f x+ %.2f = 0 \n",a,b,c);*/
/* test des coeff et resolution*/
/* a=0 ?*/
existsol1=0;
existsol2=0;
if (a==0)
{
if (b==0) /* b=0 */
{
if (c==0) /* c=0 */
{
existsol1=0/*tout x*/
/* chaine[]=(" tout x \n");*/
printf("Tout x\n");
}
else
{
existsol1=0/*c!=0*/
/* chaine[]=(" pas de solution \n");*/
printf(" pas de solution \n");
}
/* */
else /*b!=0*/
{
existsol1=1/*tout x*/
sol1=-c/b
/*chaine[]=(" 1 solution \n");*/
printf("1 solution X= %f \n",sol1);
}
}
else {
printf("%.2f x²+ %.2f x+ %.2f = 0 \n",a,b,c)
det=sqrt((pow(b,b))-4*a*c)
printf("det= %f\n",det);
if (det<0)
{
printf("det<0 \n")
existsol1=1
/* chaine[]=(" pas de solution: \n");*/
printf("pas de solution \n");
}
if (det>0)
{
sol1=(-b+det)/2*a
sol2=(-b+det)/2*a
existsol1=1
existsol2=1
/*chaine[]=(" 2 solutions: \n");*/
printf("2 solutions: X1= %2.f X2=%2.f \n",sol1,sol2);
}
if (det==0)
{
sol1=(-b+det)/2*a
existsol1=1
/* chaine[]=(" 1 solution double: \n");*/
printf("1 solution double: X=%f \n",sol1);
}
};
return 0;
}; |
Partager