学生一枚。今天看到书上有个一元二次根问题来了兴趣就 编写了一个完整的解一元二次方程根的问题。但结果差强人意。无论输入什么都是定值 实在不知道问题在哪 求指点一下
#include<stdio.h> #include<math.h> int main() { double a,b,c,disc,x1,x2,realpart,imagpart; scanf("1f%1f%1f%",&a,&b,&c); printf("the equation"); if(fabs(a)<=1e-6) //a<0 printf("is not quadratic\n");// 不是二元一次方程 else { disc=b*b-4*a*c; if(fabs(disc)<=1e-6) printf("has two equal roots:%8.4f\n",-b/(2*a)); //两等根 else if(disc>1e-6) { x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a); printf(" has two real roots:%8.4f and %8.4f\n",x1,x2); //两不相等根 } else { realpart=-b/(2*a); imagpart=sqrt(-disc)/(2*a); printf("has two different complex roots:");//两负数根 printf("%8.4f+%8.4fi",realpart,imagpart); printf("%8.4f-%8.4fi",realpart,imagpart); } } return 0; }
希望大家给一点帮助