#include <stdio.h>
#include <math.h>
int main(void)
{
float a,b,c;
float x1,x2;
float d;
printf("Input the value of a,b,c with , to separate:");
scanf("%f,%f,%f",&a,&b,&c);
printf("The quadratic equation with one unknown is %f X*X+%fX+%f\n",a,b,c);
if(a!=0)
{
d=b*b-4*a*c;
if(d==0)
{
x1=-b/2*a;
x2=x1;
printf("The solutions of equation are %f and %f\n",x1,x2);
}
else if(d>0)
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("The solutions of equation are %f and %f\n",x1,x2);
}
else
printf("The solutions of equation are %f+%fi and %f-%fi\n",-b/(2*a),sqrt(-d)/(2*a),-b/(2*a),sqrt(-d)/(2*a));
}else
printf("It's not a quadratic equation with one unknow\n");
return 0;
}
geany 编译的时候没有加 -lm 参数
可以这样修改:打开要编译的文件,点击菜单栏的生成——设置生成命令,在生成中加上-lm