[求助]求解C语言编程题
1. 求一元二次方程ax2+bx+c=0的根,实根和虚根都需考虑;请大家帮我做一下 谢谢大家了
#include<stdio.h>
#include<math.h>
main()
{float a,b,c,x,y;
clrscr();
printf("Enter coefficient for the quaderatic equation:\n");
printf("a:");
scanf("%f",&a);
printf("b:");
scanf("%f",&b);
printf("c:");
scanf("%f",&c);
if(b*b-4*a*c<0) printf("error");
else {if(a==0) {x=-b/c;
printf("The only solution is %g",x);
}
else {x=(-b+sqrt(b*b-4*a*c))/(2*a);
y=(-b-sqrt(b*b-4*a*c))/(2*a);
if(b*b-4*a*c==0) printf("The only solution is %g",x);
else{printf("The first solution is %g",x);
printf("\nThe second solution is %g",y);
}
}
}
}