#include
<math.h>
main()
{float
a,b,c,d,disc,x1,x2,realpart,imagpart;
scanf("%f,%f,%f",&a,&b,&c);
輸入系數
printf("the
equation");
屏幕打印“the
equation”
if(fabs(a)
<=le-6)-------------------1e-6是10的-6次方的意思,a為0,則為壹次方程
printf("is
not
a
quaratic");
//屏幕打印“is
not
a
quaratic”,即如果上面條件成立,屏幕上出現
//the
equation
is
not
a
quaratic;
else
{disc=b*b-4*a*c;
//根的判別式b^2-4ac
if(fabs(disc)
<=le-6
//如果等於0(接近0,因為float型的數值不會嚴格相等);
printf("has
tow
equal
roots:%8.4\n",-b/(*a));
//屏幕打印"has
tow
equal
roots
:"和(-b/a)的值;四位小數
else
if(disc>le-6)
//如果判別式值大於0,則
{x1=(-b+sqrt(disc))/(2*a);
//根據公式算出x1,x2;
{x2=(-b-sqrt(disc))/(2*a);
printf("has
distinct
real
roots:%8.4f
and%8.4f\n",x1,x2);//屏幕打印“has
distinct
real
roots”,"x1,x2
//的值"格式同上,
//接下來應該判別disc小於0的情況;
if
(disc<le-6)
{printf("has
no
real
roots");
realpart=-b/(2*a);
//實根
imagpart=sqrt(-disc)/(2*a);//虛根的模
printf("but
tow
complex
roots");
printf("the
real
part
is
%8.4f
and
the
imagpart
is
%8.4f\n
i",realpart,imagpart);//第壹個根的實部和虛部
printf("the
real
part
is
%8.4f
and
the
imagpart
is
-
%8.4f\n
i",realpart,imagpart);//第二個根的實部和虛部
}
}