/*helloworld*/
#include
void main() { printf(hello world!); } /*功能:求一元二次方程的解。*/ #include math.h main() {float a,b,c,disc,x1,x2,p,q; scanf(“%f,%f,%f”, &a, &b, &c); disc=b*b-4*a*c;
if (fabs(disc)<=1e-6) /*fabs():求绝对值库函数*/ printf(“x1=x2=%7.2f\n”, -b/(2*a)); /*输出两个相等的实根*/ else { if (disc>1e-6) {x1=(-b+sqrt(disc))/(2*a); /*求出两个不相等的实根*/ x2=(-b-sqrt(disc))/(2*a); printf(x1=%7.2f,x2=%7.2f\n, x1, x2); } else {p=-b/(2*a); /*求出两个共轭复根*/ q=sqrt(fabs(disc))/(2*a); printf(“x1=%7.2f + %7.2f i\n“, p, q); /*输出两个共轭复根*/ printf(”x2=%7.2f - %7.2f i\n“, p, q); } } } |