C语言编程:求一元二次方程的解,要求如下图,咋编?
代凯山御盯岩码文本:
#include "stdio.h"
#include "math.h"
void fp(double a,double b,double t){
b/=(a+=a);
t=sqrt(t)/a;
printf("x1 = %g\nx2 = %g\n",-b+t,-b-t);
}
void fn(double a,double b,double t){
b/=(a+=a);
t=sqrt(-t)/a;
if(b)
printf("x1 = %g+%gi\nx2 = %g-%gi\n",-b,t,-b,t);
else
printf("x1 = %gi\nx2 = %gi\n",t,-t);
}
void f0(double a,double b){
printf("x1=x2 = %g\n",-b/(a+a));
}
int main(int argc,char *argv[]){
double a,b,c,t;
printf("Enter a, b, c(R:)...\n");
if(scanf("%lf%lf%lf",&a,&b,&c)==3 &&唯宴 a)
(t=b*b-4*a*c)>0 ? fp(a,b,t) : t<0 ? fn(a,b,t) : f0(a,b);
else
printf("Input error, exit...\n");
return 0;
}