10.求方程的根

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 
 5 int main()
 6 {
 7     float  a,b,c,s,p,q,x1,x2;
 8     scanf("%f%f%f",&a,&b,&c);
 9     s = (-b)/(2*a);
10     q = b*b-4*a*c;
11     if(q>0)
12     {
13        p = sqrt(q)/(2*a);
14        x1 = s+p;
15        x2 = s-p;
16        printf("x1 = %7.2f\nx2 = %5.2f\n",x1,x2);
17     }
18 
19     else if(q==0)
20     {
21         x1 = s;
22         x2 = s;
23         printf("x1 = %7.2f\nx2 = %7.2f\n",x1,x2);
24     }
25     else
26     {
27         printf("方程无实根");
28     }
29 
30     return 0;
31 }

猜你喜欢

转载自www.cnblogs.com/spore/p/10263684.html
10.