#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c,d,p,q,x1,x2;
printf("請輸入a,b,c的值:");
scanf("%lf%lf%lf",&a,&b,&c);
d = b*b - 4*a*c;
if (d >= 0)
{
p = -b / (2.0*a);
q = sqrt(d) / (2.0*a);
x1 = p + q;
x2 = p - q;
printf("x1=%lf\nx2=%lf\n", x1, x2);//用lf輸出小數部分占6位
/*printf("x1=%7.2f\nx2=%7.2f\n", x1, x2);*///輸出指定數據占7列,小數占2列
}
else
{
printf("原方程無實數解\n");
}
return 0;
}
結果: 請輸入a,b,c的值:2 3 1 x1=-0.500000 x2=-1.000000 請按任意鍵繼續. . .