> 其他 >
c语言程序设计题目:计算一元二次方程的根
【程序填空】
#include
//
else if(【?】)
{x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("has distinct real roots:%8.4f and %.4f\n",x1,x2);
}
else
{realpart=-b/(2*a);
imagpart=sqrt(-disc)/(2*a);
printf("has complex roots:\n");
printf("%8.4f=%.4fi\n",realpart,imagpart);
printf("%8.4f-%.4fi\n",realpart,imagpart);
}
}
人气:128 ℃ 时间:2020-04-03 11:59:48
解答
#include
//
else if(disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("has distinct real roots:%8.4f and %.4f\n",x1,x2);
}
else
{
realpart=-b/(2*a);
imagpart=sqrt(-disc)/(2*a);
printf("has complex roots:\n");
printf("%8.4f+%.4fi\n",realpart,imagpart);
printf("%8.4f-%.4fi\n",realpart,imagpart);
}
}
}
2 -3 -5
the equationhas distinct real roots:2.5000 and -1.0000
Press any key to continue
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版