1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 while(1) 6 { 7 double a,b,c; 8 double delta; 9 double x1,x2; 10 char ch; 11 printf("请输入三个系数: "); 12 printf("a = "); 13 scanf("%lf",&a); 14 printf("b = "); 15 scanf("%lf",&b); 16 printf("c = "); 17 scanf("%lf",&c); 18 delta = b*b - 4*a*c; 19 if(delta > 0) 20 { 21 printf("该方程有两个解: "); 22 x1 = (-b + sqrt(delta))/(2.0*a); 23 x2 = (-b - sqrt(delta))/(2.0*a); 24 printf("x1 = %lf ",x1); 25 printf("x2 = %lf ",x2); 26 } 27 else if(delta == 0) 28 { 29 printf("该方程有唯一解: "); 30 x1 = (-b + sqrt(delta))/(2.0*a); 31 x2=x1; 32 printf("x1 = %lf ",x1); 33 printf("x2 = %lf ",x2); 34 } 35 else 36 { 37 printf("该方程无解! "); 38 } 39 40 getchar(); 41 printf("是否继续下组计算:(Y/N) "); 42 scanf("%c",&ch); 43 if(ch == 'N') 44 break; 45 } 46 return 0; 47 }