#include <stdio.h>
#include <math.h>
void fun(float a,float b,float c,float *p) //把结果保存在传入的数组里返回
{
float delta=b*b-4*a*c;
if(delta>=0)
{
p[0]=(-b+sqrt(delta))/2/a;
p[1]=(-b-sqrt(delta))/2/a;
}
else
{
p[0]=0;
p[1]=0;
}
}
int main()
{
float a, b, c,v;
float x[2]={0};//用保存结果
scanf("%f%f%f", &a, &b, &c);
v = b*b - 4 * a*c;
if (v >= 0)//不管是实数解是否相等,直接输出
//如果非要在意两个解相等的情况,把这个判断分开写就是了
{
fun(a, b, c,x);
printf("x1=%f,x2=%f\n", x[0], x[1]);
}
else
printf("输入错误,方程没有实数解.\n");
getch();
return 0;
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/060828381f30e9243f6a218340086e061c95f7b2?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)