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
| #include<stdio.h>
#include<math.h>
main() {
float x1,x2,a,b,c,d;
printf("a=");
scanf("%f" , &a);
printf("b=");
scanf("%f" , %b);
printf("c=");
scanf("%f" , &c);
d=(b*b-4*a*c);
if (a==0)
if(b!=0){
x1=-c/b;
printf(one root solution);
}
else
printf(no solution);
else if (a!=0){
if (d>0){
x1=(-b-sqrt(d)/2*a);
x2=(-b+sqrt(d)/2*a);
printf("root is%f\n", x1);
printf("root is%f\n", x2);
}
else if (d==0)
x1=-b/2*a;
x2=x1;
printf("only one root%f\n", x1);
else (d<0){
printf("no roots%f\n");
} |
Partager