[函数] #include<stdio.h> #include<stdlib.h> #include<math.h> Main() { float a,b,c,delta,x1,x2; printf("Enter a,b,c"); scanf("%f%f%f",&a,&b,&c)); if(______) if(______) printf("Input error!\n"); else printf("The single root is %f\n",______); else { delta=b*b-4*a*c; if(______) { x1=(-b+sqrt(delta))/(2*a); x2=(-b-sqrt(delta))/(2*a); printf("x1=%8.2f\nx2=%8.2f\n",x1,x2,); } else if(delta==0) printf("x1=x2=%8.2f\n",______); else { Printf("z2=%8.2f+%8.2f*i\n",-b/(2*a),sqrt(-delta)/)(2*abs(a))); Printf("z2=%8.2f-%8.2f*i\n",-b/(2*a),sqrt(-delta)/(2*abs(a))); } } }
时间: 2023-12-16 11:03:36 浏览: 130
在代码中,if语句中的第一个条件应该是a==0,第二个条件应该是c==0,单根的输出应该为-x2/(2*a),delta为0时单根和两根相等的输出应该为-x1/(2*a)。修改后的代码如下:
```c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
float a, b, c, delta, x1, x2;
printf("Enter a, b, c: ");
scanf("%f%f%f", &a, &b, &c);
if (a == 0) {
printf("Input error!\n");
} else if (c == 0) {
x1 = 0;
x2 = -b / a;
printf("x1 = %8.2f\nx2 = %8.2f\n", x1, x2);
} else {
delta = b * b - 4 * a * c;
if (delta > 0) {
x1 = (-b + sqrt(delta)) / (2 * a);
x2 = (-b - sqrt(delta)) / (2 * a);
printf("x1 = %8.2f\nx2 = %8.2f\n", x1, x2);
} else if (delta == 0) {
x1 = x2 = -b / (2 * a);
printf("x1 = x2 = %8.2f\n", x1);
} else {
printf("z1 = %8.2f + %8.2fi\n", -b / (2 * a), sqrt(-delta) / (2 * abs(a)));
printf("z2 = %8.2f - %8.2fi\n", -b / (2 * a), sqrt(-delta) / (2 * abs(a)));
}
}
return 0;
}
```
阅读全文
相关推荐


















